WIP: development_backend #4
@@ -1,4 +1,4 @@
 | 
			
		||||
use crate::db::proposals;
 | 
			
		||||
use crate::db::proposals::{self, get_proposal_by_id};
 | 
			
		||||
use crate::models::governance::{Vote, VoteType, VotingResults};
 | 
			
		||||
use crate::utils::render_template;
 | 
			
		||||
use actix_session::Session;
 | 
			
		||||
@@ -126,8 +126,8 @@ impl GovernanceController {
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Get mock proposal detail
 | 
			
		||||
        let proposal = Self::get_mock_proposal_by_id(&proposal_id);
 | 
			
		||||
        if let Some(proposal) = proposal {
 | 
			
		||||
        let proposal = get_proposal_by_id(proposal_id.parse().unwrap());
 | 
			
		||||
        if let Ok(Some(proposal)) = proposal {
 | 
			
		||||
            ctx.insert("proposal", &proposal);
 | 
			
		||||
 | 
			
		||||
            // Get mock votes for this proposal
 | 
			
		||||
 
 | 
			
		||||
@@ -75,3 +75,18 @@ pub fn get_proposals() -> Result<Vec<Proposal>, String> {
 | 
			
		||||
    };
 | 
			
		||||
    Ok(proposals)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// Fetches a single proposal by its ID from the database.
 | 
			
		||||
pub fn get_proposal_by_id(proposal_id: u32) -> Result<Option<Proposal>, String> {
 | 
			
		||||
    let db = get_db(DB_PATH).map_err(|e| format!("DB error: {}", e))?;
 | 
			
		||||
    let collection = db
 | 
			
		||||
        .collection::<Proposal>()
 | 
			
		||||
        .map_err(|e| format!("Collection error: {:?}", e))?;
 | 
			
		||||
    match collection.get_by_id(proposal_id) {
 | 
			
		||||
        Ok(proposal) => Ok(Some(proposal.expect("proposal not found"))),
 | 
			
		||||
        Err(e) => {
 | 
			
		||||
            eprintln!("Error fetching proposal by id {}: {:?}", proposal_id, e);
 | 
			
		||||
            Err(format!("Failed to fetch proposal: {:?}", e))
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -3,133 +3,136 @@
 | 
			
		||||
{% block title %}My Votes - Governance Dashboard{% endblock %}
 | 
			
		||||
 | 
			
		||||
{% block content %}
 | 
			
		||||
    <!-- Navigation Tabs -->
 | 
			
		||||
    <div class="row mb-4">
 | 
			
		||||
        <div class="col-12">
 | 
			
		||||
            <ul class="nav nav-tabs">
 | 
			
		||||
                <li class="nav-item">
 | 
			
		||||
                    <a class="nav-link" href="/governance">Dashboard</a>
 | 
			
		||||
                </li>
 | 
			
		||||
                <li class="nav-item">
 | 
			
		||||
                    <a class="nav-link" href="/governance/proposals">All Proposals</a>
 | 
			
		||||
                </li>
 | 
			
		||||
                <li class="nav-item">
 | 
			
		||||
                    <a class="nav-link active" href="/governance/my-votes">My Votes</a>
 | 
			
		||||
                </li>
 | 
			
		||||
                <li class="nav-item">
 | 
			
		||||
                    <a class="nav-link" href="/governance/create">Create Proposal</a>
 | 
			
		||||
                </li>
 | 
			
		||||
            </ul>
 | 
			
		||||
<!-- Navigation Tabs -->
 | 
			
		||||
<div class="row mb-4">
 | 
			
		||||
    <div class="col-12">
 | 
			
		||||
        <ul class="nav nav-tabs">
 | 
			
		||||
            <li class="nav-item">
 | 
			
		||||
                <a class="nav-link" href="/governance">Dashboard</a>
 | 
			
		||||
            </li>
 | 
			
		||||
            <li class="nav-item">
 | 
			
		||||
                <a class="nav-link" href="/governance/proposals">All Proposals</a>
 | 
			
		||||
            </li>
 | 
			
		||||
            <li class="nav-item">
 | 
			
		||||
                <a class="nav-link active" href="/governance/my-votes">My Votes</a>
 | 
			
		||||
            </li>
 | 
			
		||||
            <li class="nav-item">
 | 
			
		||||
                <a class="nav-link" href="/governance/create">Create Proposal</a>
 | 
			
		||||
            </li>
 | 
			
		||||
        </ul>
 | 
			
		||||
    </div>
 | 
			
		||||
</div>
 | 
			
		||||
 | 
			
		||||
<!-- My Votes List -->
 | 
			
		||||
<div class="row mb-4">
 | 
			
		||||
    <div class="col-12">
 | 
			
		||||
        <div class="card">
 | 
			
		||||
            <div class="card-header">
 | 
			
		||||
                <h5 class="mb-0">My Voting History</h5>
 | 
			
		||||
            </div>
 | 
			
		||||
            <div class="card-body">
 | 
			
		||||
                {% if votes | length > 0 %}
 | 
			
		||||
                <div class="table-responsive">
 | 
			
		||||
                    <table class="table table-hover">
 | 
			
		||||
                        <thead>
 | 
			
		||||
                            <tr>
 | 
			
		||||
                                <th>Proposal</th>
 | 
			
		||||
                                <th>My Vote</th>
 | 
			
		||||
                                <th>Status</th>
 | 
			
		||||
                                <th>Voted On</th>
 | 
			
		||||
                                <th>Actions</th>
 | 
			
		||||
                            </tr>
 | 
			
		||||
                        </thead>
 | 
			
		||||
                        <tbody>
 | 
			
		||||
                            {% for item in votes %}{% set vote = item.0 %}{% set proposal = item.1 %}
 | 
			
		||||
                            <tr>
 | 
			
		||||
                                <td>{{ proposal.title }}</td>
 | 
			
		||||
                                <td>
 | 
			
		||||
                                    <span
 | 
			
		||||
                                        class="badge {% if vote.vote_type == 'Yes' %}bg-success{% elif vote.vote_type == 'No' %}bg-danger{% else %}bg-secondary{% endif %}">
 | 
			
		||||
                                        {{ vote.vote_type }}
 | 
			
		||||
                                    </span>
 | 
			
		||||
                                </td>
 | 
			
		||||
                                <td>
 | 
			
		||||
                                    <span
 | 
			
		||||
                                        class="badge {% if proposal.status == 'Active' %}bg-success{% elif proposal.status == 'Approved' %}bg-primary{% elif proposal.status == 'Rejected' %}bg-danger{% elif proposal.status == 'Draft' %}bg-secondary{% else %}bg-warning{% endif %}">
 | 
			
		||||
                                        {{ proposal.status }}
 | 
			
		||||
                                    </span>
 | 
			
		||||
                                </td>
 | 
			
		||||
                                <td>{{ vote.created_at | date(format="%Y-%m-%d") }}</td>
 | 
			
		||||
                                <td>
 | 
			
		||||
                                    <a href="/governance/proposals/{{ proposal.base_data.id }}"
 | 
			
		||||
                                        class="btn btn-sm btn-primary">View Proposal</a>
 | 
			
		||||
                                </td>
 | 
			
		||||
                            </tr>
 | 
			
		||||
                            {% endfor %}
 | 
			
		||||
                        </tbody>
 | 
			
		||||
                    </table>
 | 
			
		||||
                </div>
 | 
			
		||||
                {% else %}
 | 
			
		||||
                <div class="text-center py-5">
 | 
			
		||||
                    <i class="bi bi-clipboard-check fs-1 text-muted mb-3"></i>
 | 
			
		||||
                    <h5>You haven't voted on any proposals yet</h5>
 | 
			
		||||
                    <p class="text-muted">When you vote on proposals, they will appear here.</p>
 | 
			
		||||
                    <a href="/governance/proposals" class="btn btn-primary mt-3">Browse Proposals</a>
 | 
			
		||||
                </div>
 | 
			
		||||
                {% endif %}
 | 
			
		||||
            </div>
 | 
			
		||||
        </div>
 | 
			
		||||
    </div>
 | 
			
		||||
</div>
 | 
			
		||||
 | 
			
		||||
    <!-- My Votes List -->
 | 
			
		||||
    <div class="row mb-4">
 | 
			
		||||
        <div class="col-12">
 | 
			
		||||
            <div class="card">
 | 
			
		||||
                <div class="card-header">
 | 
			
		||||
                    <h5 class="mb-0">My Voting History</h5>
 | 
			
		||||
                </div>
 | 
			
		||||
                <div class="card-body">
 | 
			
		||||
                    {% if votes | length > 0 %}
 | 
			
		||||
                    <div class="table-responsive">
 | 
			
		||||
                        <table class="table table-hover">
 | 
			
		||||
                            <thead>
 | 
			
		||||
                                <tr>
 | 
			
		||||
                                    <th>Proposal</th>
 | 
			
		||||
                                    <th>My Vote</th>
 | 
			
		||||
                                    <th>Status</th>
 | 
			
		||||
                                    <th>Voted On</th>
 | 
			
		||||
                                    <th>Actions</th>
 | 
			
		||||
                                </tr>
 | 
			
		||||
                            </thead>
 | 
			
		||||
                            <tbody>
 | 
			
		||||
                                {% for item in votes %}{% set vote = item.0 %}{% set proposal = item.1 %}
 | 
			
		||||
                                <tr>
 | 
			
		||||
                                    <td>{{ proposal.title }}</td>
 | 
			
		||||
                                    <td>
 | 
			
		||||
                                        <span class="badge {% if vote.vote_type == 'Yes' %}bg-success{% elif vote.vote_type == 'No' %}bg-danger{% else %}bg-secondary{% endif %}">
 | 
			
		||||
                                            {{ vote.vote_type }}
 | 
			
		||||
                                        </span>
 | 
			
		||||
                                    </td>
 | 
			
		||||
                                    <td>
 | 
			
		||||
                                        <span class="badge {% if proposal.status == 'Active' %}bg-success{% elif proposal.status == 'Approved' %}bg-primary{% elif proposal.status == 'Rejected' %}bg-danger{% elif proposal.status == 'Draft' %}bg-secondary{% else %}bg-warning{% endif %}">
 | 
			
		||||
                                            {{ proposal.status }}
 | 
			
		||||
                                        </span>
 | 
			
		||||
                                    </td>
 | 
			
		||||
                                    <td>{{ vote.created_at | date(format="%Y-%m-%d") }}</td>
 | 
			
		||||
                                    <td>
 | 
			
		||||
                                        <a href="/governance/proposals/{{ proposal.id }}" class="btn btn-sm btn-primary">View Proposal</a>
 | 
			
		||||
                                    </td>
 | 
			
		||||
                                </tr>
 | 
			
		||||
                                {% endfor %}
 | 
			
		||||
                            </tbody>
 | 
			
		||||
                        </table>
 | 
			
		||||
                    </div>
 | 
			
		||||
                    {% else %}
 | 
			
		||||
                    <div class="text-center py-5">
 | 
			
		||||
                        <i class="bi bi-clipboard-check fs-1 text-muted mb-3"></i>
 | 
			
		||||
                        <h5>You haven't voted on any proposals yet</h5>
 | 
			
		||||
                        <p class="text-muted">When you vote on proposals, they will appear here.</p>
 | 
			
		||||
                        <a href="/governance/proposals" class="btn btn-primary mt-3">Browse Proposals</a>
 | 
			
		||||
                    </div>
 | 
			
		||||
<!-- Voting Stats -->
 | 
			
		||||
{% if votes | length > 0 %}
 | 
			
		||||
<div class="row mb-4">
 | 
			
		||||
    <div class="col-md-4 mb-3">
 | 
			
		||||
        <div class="card text-white bg-success h-100">
 | 
			
		||||
            <div class="card-body text-center">
 | 
			
		||||
                <h5 class="card-title">Yes Votes</h5>
 | 
			
		||||
                <p class="display-4">
 | 
			
		||||
                    {% set yes_count = 0 %}
 | 
			
		||||
                    {% for item in votes %}{% set vote = item.0 %}{% set proposal = item.1 %}
 | 
			
		||||
                    {% if vote.vote_type == 'Yes' %}
 | 
			
		||||
                    {% set yes_count = yes_count + 1 %}
 | 
			
		||||
                    {% endif %}
 | 
			
		||||
                </div>
 | 
			
		||||
                    {% endfor %}
 | 
			
		||||
                    {{ yes_count }}
 | 
			
		||||
                </p>
 | 
			
		||||
            </div>
 | 
			
		||||
        </div>
 | 
			
		||||
    </div>
 | 
			
		||||
 | 
			
		||||
    <!-- Voting Stats -->
 | 
			
		||||
    {% if votes | length > 0 %}
 | 
			
		||||
    <div class="row mb-4">
 | 
			
		||||
        <div class="col-md-4 mb-3">
 | 
			
		||||
            <div class="card text-white bg-success h-100">
 | 
			
		||||
                <div class="card-body text-center">
 | 
			
		||||
                    <h5 class="card-title">Yes Votes</h5>
 | 
			
		||||
                    <p class="display-4">
 | 
			
		||||
                        {% set yes_count = 0 %}
 | 
			
		||||
                        {% for item in votes %}{% set vote = item.0 %}{% set proposal = item.1 %}
 | 
			
		||||
                            {% if vote.vote_type == 'Yes' %}
 | 
			
		||||
                                {% set yes_count = yes_count + 1 %}
 | 
			
		||||
                            {% endif %}
 | 
			
		||||
                        {% endfor %}
 | 
			
		||||
                        {{ yes_count }}
 | 
			
		||||
                    </p>
 | 
			
		||||
                </div>
 | 
			
		||||
            </div>
 | 
			
		||||
        </div>
 | 
			
		||||
        <div class="col-md-4 mb-3">
 | 
			
		||||
            <div class="card text-white bg-danger h-100">
 | 
			
		||||
                <div class="card-body text-center">
 | 
			
		||||
                    <h5 class="card-title">No Votes</h5>
 | 
			
		||||
                    <p class="display-4">
 | 
			
		||||
                        {% set no_count = 0 %}
 | 
			
		||||
                        {% for item in votes %}{% set vote = item.0 %}{% set proposal = item.1 %}
 | 
			
		||||
                            {% if vote.vote_type == 'No' %}
 | 
			
		||||
                                {% set no_count = no_count + 1 %}
 | 
			
		||||
                            {% endif %}
 | 
			
		||||
                        {% endfor %}
 | 
			
		||||
                        {{ no_count }}
 | 
			
		||||
                    </p>
 | 
			
		||||
                </div>
 | 
			
		||||
            </div>
 | 
			
		||||
        </div>
 | 
			
		||||
        <div class="col-md-4 mb-3">
 | 
			
		||||
            <div class="card text-white bg-secondary h-100">
 | 
			
		||||
                <div class="card-body text-center">
 | 
			
		||||
                    <h5 class="card-title">Abstain Votes</h5>
 | 
			
		||||
                    <p class="display-4">
 | 
			
		||||
                        {% set abstain_count = 0 %}
 | 
			
		||||
                        {% for item in votes %}{% set vote = item.0 %}{% set proposal = item.1 %}
 | 
			
		||||
                            {% if vote.vote_type == 'Abstain' %}
 | 
			
		||||
                                {% set abstain_count = abstain_count + 1 %}
 | 
			
		||||
                            {% endif %}
 | 
			
		||||
                        {% endfor %}
 | 
			
		||||
                        {{ abstain_count }}
 | 
			
		||||
                    </p>
 | 
			
		||||
                </div>
 | 
			
		||||
    <div class="col-md-4 mb-3">
 | 
			
		||||
        <div class="card text-white bg-danger h-100">
 | 
			
		||||
            <div class="card-body text-center">
 | 
			
		||||
                <h5 class="card-title">No Votes</h5>
 | 
			
		||||
                <p class="display-4">
 | 
			
		||||
                    {% set no_count = 0 %}
 | 
			
		||||
                    {% for item in votes %}{% set vote = item.0 %}{% set proposal = item.1 %}
 | 
			
		||||
                    {% if vote.vote_type == 'No' %}
 | 
			
		||||
                    {% set no_count = no_count + 1 %}
 | 
			
		||||
                    {% endif %}
 | 
			
		||||
                    {% endfor %}
 | 
			
		||||
                    {{ no_count }}
 | 
			
		||||
                </p>
 | 
			
		||||
            </div>
 | 
			
		||||
        </div>
 | 
			
		||||
    </div>
 | 
			
		||||
    {% endif %}
 | 
			
		||||
{% endblock %}
 | 
			
		||||
    <div class="col-md-4 mb-3">
 | 
			
		||||
        <div class="card text-white bg-secondary h-100">
 | 
			
		||||
            <div class="card-body text-center">
 | 
			
		||||
                <h5 class="card-title">Abstain Votes</h5>
 | 
			
		||||
                <p class="display-4">
 | 
			
		||||
                    {% set abstain_count = 0 %}
 | 
			
		||||
                    {% for item in votes %}{% set vote = item.0 %}{% set proposal = item.1 %}
 | 
			
		||||
                    {% if vote.vote_type == 'Abstain' %}
 | 
			
		||||
                    {% set abstain_count = abstain_count + 1 %}
 | 
			
		||||
                    {% endif %}
 | 
			
		||||
                    {% endfor %}
 | 
			
		||||
                    {{ abstain_count }}
 | 
			
		||||
                </p>
 | 
			
		||||
            </div>
 | 
			
		||||
        </div>
 | 
			
		||||
    </div>
 | 
			
		||||
</div>
 | 
			
		||||
{% endif %}
 | 
			
		||||
{% endblock %}
 | 
			
		||||
@@ -107,7 +107,7 @@
 | 
			
		||||
                    <h5 class="mb-0">Cast Your Vote</h5>
 | 
			
		||||
                </div>
 | 
			
		||||
                <div class="card-body">
 | 
			
		||||
                    <form action="/governance/proposals/{{ proposal.id }}/vote" method="post">
 | 
			
		||||
                    <form action="/governance/proposals/{{ proposal.base_data.id }}/vote" method="post">
 | 
			
		||||
                        <div class="mb-3">
 | 
			
		||||
                            <label class="form-label">Vote Type</label>
 | 
			
		||||
                            <div class="form-check">
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user