feat: Implement Proposals page:
- Added the create new proposal functionality - Added the list all proposals functionnality
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
use crate::db::proposals;
|
||||
use crate::models::governance::{Proposal, ProposalStatus, Vote, VoteType, VotingResults};
|
||||
use crate::models::governance::{Vote, VoteType, VotingResults};
|
||||
use crate::utils::render_template;
|
||||
use actix_session::Session;
|
||||
use actix_web::{HttpResponse, Responder, Result, web};
|
||||
use chrono::{Duration, Utc};
|
||||
use heromodels::models::governance::{Proposal, ProposalStatus};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::Value;
|
||||
use tera::Tera;
|
||||
@@ -48,18 +49,24 @@ impl GovernanceController {
|
||||
let user = Self::get_user_from_session(&session).unwrap();
|
||||
ctx.insert("user", &user);
|
||||
|
||||
// Get mock proposals for the dashboard
|
||||
let proposals = Self::get_mock_proposals();
|
||||
// Get proposals from the database
|
||||
let proposals = match crate::db::proposals::get_proposals() {
|
||||
Ok(props) => props,
|
||||
Err(e) => {
|
||||
ctx.insert("error", &format!("Failed to load proposals: {}", e));
|
||||
vec![]
|
||||
}
|
||||
};
|
||||
|
||||
// Filter for active proposals only
|
||||
let active_proposals: Vec<Proposal> = proposals
|
||||
let active_proposals: Vec<heromodels::models::Proposal> = proposals
|
||||
.into_iter()
|
||||
.filter(|p| p.status == ProposalStatus::Active)
|
||||
.filter(|p| p.status == heromodels::models::ProposalStatus::Active)
|
||||
.collect();
|
||||
|
||||
// Sort active proposals by voting end date (ascending)
|
||||
let mut sorted_active_proposals = active_proposals.clone();
|
||||
sorted_active_proposals.sort_by(|a, b| a.voting_ends_at.cmp(&b.voting_ends_at));
|
||||
sorted_active_proposals.sort_by(|a, b| a.vote_start_date.cmp(&b.vote_end_date));
|
||||
|
||||
ctx.insert("proposals", &sorted_active_proposals);
|
||||
|
||||
@@ -90,8 +97,14 @@ impl GovernanceController {
|
||||
ctx.insert("user", &user);
|
||||
}
|
||||
|
||||
// Get mock proposals
|
||||
let proposals = Self::get_mock_proposals();
|
||||
// Get proposals from the database
|
||||
let proposals = match crate::db::proposals::get_proposals() {
|
||||
Ok(props) => props,
|
||||
Err(e) => {
|
||||
ctx.insert("error", &format!("Failed to load proposals: {}", e));
|
||||
vec![]
|
||||
}
|
||||
};
|
||||
ctx.insert("proposals", &proposals);
|
||||
|
||||
render_template(&tmpl, "governance/proposals.html", &ctx)
|
||||
@@ -199,10 +212,24 @@ impl GovernanceController {
|
||||
.unwrap_or(1)
|
||||
.to_string();
|
||||
|
||||
let user_name = user
|
||||
.get("username")
|
||||
.and_then(|v| v.as_str())
|
||||
.unwrap_or("Test User")
|
||||
.to_string();
|
||||
|
||||
let is_draft = _form.draft.is_some();
|
||||
let status = if is_draft {
|
||||
ProposalStatus::Draft
|
||||
} else {
|
||||
ProposalStatus::Active
|
||||
};
|
||||
match proposals::create_new_proposal(
|
||||
&user_id,
|
||||
&user_name,
|
||||
proposal_title,
|
||||
proposal_description,
|
||||
status,
|
||||
voting_start_date,
|
||||
voting_end_date,
|
||||
) {
|
||||
@@ -221,8 +248,14 @@ impl GovernanceController {
|
||||
|
||||
// For now, we'll just redirect to the proposals page with a success message
|
||||
|
||||
// Get mock proposals
|
||||
let proposals = Self::get_mock_proposals();
|
||||
// Get proposals from the database
|
||||
let proposals = match crate::db::proposals::get_proposals() {
|
||||
Ok(props) => props,
|
||||
Err(e) => {
|
||||
ctx.insert("error", &format!("Failed to load proposals: {}", e));
|
||||
vec![]
|
||||
}
|
||||
};
|
||||
ctx.insert("proposals", &proposals);
|
||||
|
||||
render_template(&tmpl, "governance/proposals.html", &ctx)
|
||||
@@ -371,96 +404,98 @@ impl GovernanceController {
|
||||
fn get_mock_proposals() -> Vec<Proposal> {
|
||||
let now = Utc::now();
|
||||
vec![
|
||||
Proposal {
|
||||
id: "prop-001".to_string(),
|
||||
creator_id: 1,
|
||||
creator_name: "Ibrahim Faraji".to_string(),
|
||||
title: "Establish Zanzibar Digital Trade Hub".to_string(),
|
||||
description: "This proposal aims to create a dedicated digital trade hub within the Zanzibar Digital Freezone to facilitate international e-commerce for local businesses. The hub will provide logistics support, digital marketing services, and regulatory compliance assistance to help Zanzibar businesses reach global markets.".to_string(),
|
||||
status: ProposalStatus::Active,
|
||||
created_at: now - Duration::days(5),
|
||||
updated_at: now - Duration::days(5),
|
||||
voting_starts_at: Some(now - Duration::days(3)),
|
||||
voting_ends_at: Some(now + Duration::days(4)),
|
||||
},
|
||||
Proposal {
|
||||
id: "prop-002".to_string(),
|
||||
creator_id: 2,
|
||||
creator_name: "Amina Salim".to_string(),
|
||||
title: "ZDFZ Sustainable Tourism Framework".to_string(),
|
||||
description: "A comprehensive framework for sustainable tourism development within the Zanzibar Digital Freezone. This proposal outlines environmental standards, community benefit-sharing mechanisms, and digital infrastructure for eco-tourism businesses. It includes tokenization standards for tourism assets and a certification system for sustainable operators.".to_string(),
|
||||
status: ProposalStatus::Approved,
|
||||
created_at: now - Duration::days(15),
|
||||
updated_at: now - Duration::days(2),
|
||||
voting_starts_at: Some(now - Duration::days(14)),
|
||||
voting_ends_at: Some(now - Duration::days(2)),
|
||||
},
|
||||
Proposal {
|
||||
id: "prop-003".to_string(),
|
||||
creator_id: 3,
|
||||
creator_name: "Hassan Mwinyi".to_string(),
|
||||
title: "Spice Industry Modernization Initiative".to_string(),
|
||||
description: "This proposal seeks to modernize Zanzibar's traditional spice industry through blockchain-based supply chain tracking, international quality certification, and digital marketplace integration. The initiative will help local spice farmers and processors access premium international markets while preserving traditional cultivation methods.".to_string(),
|
||||
status: ProposalStatus::Draft,
|
||||
created_at: now - Duration::days(1),
|
||||
updated_at: now - Duration::days(1),
|
||||
voting_starts_at: None,
|
||||
voting_ends_at: None,
|
||||
},
|
||||
Proposal {
|
||||
id: "prop-004".to_string(),
|
||||
creator_id: 1,
|
||||
creator_name: "Ibrahim Faraji".to_string(),
|
||||
title: "ZDFZ Regulatory Framework for Digital Financial Services".to_string(),
|
||||
description: "Establish a comprehensive regulatory framework for digital financial services within the Zanzibar Digital Freezone. This includes licensing requirements for crypto exchanges, digital payment providers, and tokenized asset platforms operating within the zone, while ensuring compliance with international AML/KYC standards.".to_string(),
|
||||
status: ProposalStatus::Rejected,
|
||||
created_at: now - Duration::days(20),
|
||||
updated_at: now - Duration::days(5),
|
||||
voting_starts_at: Some(now - Duration::days(19)),
|
||||
voting_ends_at: Some(now - Duration::days(5)),
|
||||
},
|
||||
Proposal {
|
||||
id: "prop-005".to_string(),
|
||||
creator_id: 4,
|
||||
creator_name: "Fatma Busaidy".to_string(),
|
||||
title: "Digital Arts Incubator and Artwork Marketplace".to_string(),
|
||||
description: "Create a dedicated digital arts incubator and Artwork marketplace to support Zanzibar's creative economy. The initiative will provide technical training, equipment, and a curated marketplace for local artists to create and sell digital art that celebrates Zanzibar's rich cultural heritage while accessing global markets.".to_string(),
|
||||
status: ProposalStatus::Active,
|
||||
created_at: now - Duration::days(7),
|
||||
updated_at: now - Duration::days(7),
|
||||
voting_starts_at: Some(now - Duration::days(6)),
|
||||
voting_ends_at: Some(now + Duration::days(1)),
|
||||
},
|
||||
Proposal {
|
||||
id: "prop-006".to_string(),
|
||||
creator_id: 5,
|
||||
creator_name: "Omar Makame".to_string(),
|
||||
title: "Zanzibar Renewable Energy Microgrid Network".to_string(),
|
||||
description: "Develop a network of renewable energy microgrids across the Zanzibar Digital Freezone using tokenized investment and community ownership models. This proposal outlines the technical specifications, governance structure, and token economics for deploying solar and tidal energy systems that will ensure energy independence for the zone.".to_string(),
|
||||
status: ProposalStatus::Active,
|
||||
created_at: now - Duration::days(10),
|
||||
updated_at: now - Duration::days(9),
|
||||
voting_starts_at: Some(now - Duration::days(8)),
|
||||
voting_ends_at: Some(now + Duration::days(6)),
|
||||
},
|
||||
Proposal {
|
||||
id: "prop-007".to_string(),
|
||||
creator_id: 6,
|
||||
creator_name: "Saida Juma".to_string(),
|
||||
title: "ZDFZ Educational Technology Initiative".to_string(),
|
||||
description: "Establish a comprehensive educational technology program within the Zanzibar Digital Freezone to develop local tech talent. This initiative includes coding academies, blockchain development courses, and digital entrepreneurship training, with a focus on preparing Zanzibar's youth for careers in the zone's growing digital economy.".to_string(),
|
||||
status: ProposalStatus::Draft,
|
||||
created_at: now - Duration::days(3),
|
||||
updated_at: now - Duration::days(2),
|
||||
voting_starts_at: None,
|
||||
voting_ends_at: None,
|
||||
},
|
||||
Proposal::new(
|
||||
Some(1),
|
||||
"1",
|
||||
"Ibrahim Faraji",
|
||||
"Establish Zanzibar Digital Trade Hub",
|
||||
"This proposal aims to create a dedicated digital trade hub within the Zanzibar Digital Freezone to facilitate international e-commerce for local businesses. The hub will provide logistics support, digital marketing services, and regulatory compliance assistance to help Zanzibar businesses reach global markets.",
|
||||
ProposalStatus::Active,
|
||||
now - Duration::days(5),
|
||||
now - Duration::days(5),
|
||||
now - Duration::days(3),
|
||||
now + Duration::days(4),
|
||||
),
|
||||
Proposal::new(
|
||||
Some(2),
|
||||
"2",
|
||||
"Amina Salim",
|
||||
"ZDFZ Sustainable Tourism Framework",
|
||||
"A comprehensive framework for sustainable tourism development within the Zanzibar Digital Freezone. This proposal outlines environmental standards, community benefit-sharing mechanisms, and digital infrastructure for eco-tourism businesses. It includes tokenization standards for tourism assets and a certification system for sustainable operators.",
|
||||
ProposalStatus::Approved,
|
||||
now - Duration::days(15),
|
||||
now - Duration::days(2),
|
||||
now - Duration::days(14),
|
||||
now - Duration::days(2),
|
||||
),
|
||||
Proposal::new(
|
||||
Some(3),
|
||||
"3",
|
||||
"Hassan Mwinyi",
|
||||
"Spice Industry Modernization Initiative",
|
||||
"This proposal seeks to modernize Zanzibar's traditional spice industry through blockchain-based supply chain tracking, international quality certification, and digital marketplace integration. The initiative will help local spice farmers and processors access premium international markets while preserving traditional cultivation methods.",
|
||||
ProposalStatus::Draft,
|
||||
now - Duration::days(1),
|
||||
now - Duration::days(1),
|
||||
now - Duration::days(1),
|
||||
now + Duration::days(1),
|
||||
),
|
||||
Proposal::new(
|
||||
Some(4),
|
||||
"4",
|
||||
"Ibrahim Faraji",
|
||||
"ZDFZ Regulatory Framework for Digital Financial Services",
|
||||
"Establish a comprehensive regulatory framework for digital financial services within the Zanzibar Digital Freezone. This includes licensing requirements for crypto exchanges, digital payment providers, and tokenized asset platforms operating within the zone, while ensuring compliance with international AML/KYC standards.",
|
||||
ProposalStatus::Rejected,
|
||||
now - Duration::days(20),
|
||||
now - Duration::days(5),
|
||||
now - Duration::days(19),
|
||||
now - Duration::days(5),
|
||||
),
|
||||
Proposal::new(
|
||||
Some(5),
|
||||
"5",
|
||||
"Fatma Busaidy",
|
||||
"Digital Arts Incubator and Artwork Marketplace",
|
||||
"Create a dedicated digital arts incubator and Artwork marketplace to support Zanzibar's creative economy. The initiative will provide technical training, equipment, and a curated marketplace for local artists to create and sell digital art that celebrates Zanzibar's rich cultural heritage while accessing global markets.",
|
||||
ProposalStatus::Active,
|
||||
now - Duration::days(7),
|
||||
now - Duration::days(7),
|
||||
now - Duration::days(6),
|
||||
now + Duration::days(1),
|
||||
),
|
||||
Proposal::new(
|
||||
Some(6),
|
||||
"6",
|
||||
"Omar Makame",
|
||||
"Zanzibar Renewable Energy Microgrid Network",
|
||||
"Develop a network of renewable energy microgrids across the Zanzibar Digital Freezone using tokenized investment and community ownership models. This proposal outlines the technical specifications, governance structure, and token economics for deploying solar and tidal energy systems that will ensure energy independence for the zone.",
|
||||
ProposalStatus::Active,
|
||||
now - Duration::days(10),
|
||||
now - Duration::days(9),
|
||||
now - Duration::days(8),
|
||||
now + Duration::days(6),
|
||||
),
|
||||
Proposal::new(
|
||||
Some(7),
|
||||
"7",
|
||||
"Saida Juma",
|
||||
"ZDFZ Educational Technology Initiative",
|
||||
"Establish a comprehensive educational technology program within the Zanzibar Digital Freezone to develop local tech talent. This initiative includes coding academies, blockchain development courses, and digital entrepreneurship training, with a focus on preparing Zanzibar's youth for careers in the zone's growing digital economy.",
|
||||
ProposalStatus::Draft,
|
||||
now - Duration::days(3),
|
||||
now - Duration::days(2),
|
||||
now - Duration::days(1),
|
||||
now + Duration::days(1),
|
||||
),
|
||||
]
|
||||
}
|
||||
|
||||
/// Get a mock proposal by ID
|
||||
fn get_mock_proposal_by_id(id: &str) -> Option<Proposal> {
|
||||
Self::get_mock_proposals().into_iter().find(|p| p.id == id)
|
||||
Self::get_mock_proposals()
|
||||
.into_iter()
|
||||
.find(|p| p.base_data.id.to_string() == id)
|
||||
}
|
||||
|
||||
/// Generate mock votes for a specific proposal
|
||||
@@ -561,7 +596,7 @@ impl GovernanceController {
|
||||
.filter_map(|vote| {
|
||||
proposals
|
||||
.iter()
|
||||
.find(|p| p.id == vote.proposal_id)
|
||||
.find(|p| p.base_data.id.to_string() == vote.proposal_id)
|
||||
.map(|p| (vote.clone(), p.clone()))
|
||||
})
|
||||
.collect()
|
||||
@@ -600,6 +635,8 @@ pub struct ProposalForm {
|
||||
pub title: String,
|
||||
/// Description of the proposal
|
||||
pub description: String,
|
||||
/// Status of the proposal
|
||||
pub draft: Option<bool>,
|
||||
/// Start date for voting
|
||||
pub voting_start_date: Option<String>,
|
||||
/// End date for voting
|
||||
|
Reference in New Issue
Block a user