Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

view_proposals_page.gno

1.51 Kb · 42 lines
 1package basedao
 2
 3import (
 4	"gno.land/p/moul/md"
 5	"gno.land/p/nt/ufmt/v0"
 6	"gno.land/p/samcrew/daokit"
 7)
 8
 9func (d *DAOPrivate) ProposalsPageView(path string) string {
10	return d.ProposalsHeaderView() +
11		d.ProposalsView(path)
12}
13
14func (d *DAOPrivate) ProposalsHeaderView() string {
15	pkgPath := d.Realm.PkgPath()
16	linkPath := getLinkPath(pkgPath)
17	name := d.GetProfileString(d.Realm.Address(), "DisplayName", "DAO")
18	s := ""
19	s += ufmt.Sprintf("# %s - Proposals\n\n", name)
20	s += md.Link("> Go to the Proposal history 📜", ufmt.Sprintf("%s:%s", linkPath, PROPOSAL_HISTORY_PATH)) + "\n\n"
21	s += md.Link("Add a new proposal 🗳️", ufmt.Sprintf("%s$help", linkPath)) + "\n\n"
22	s += ufmt.Sprintf("\n--------------------------------\n")
23	return s
24}
25
26func (d *DAOPrivate) ProposalsView(path string) string {
27	activeProposals := d.Core.Proposals.GetProposals(
28		func(p daokit.Proposal) bool {
29			// Raw status, not DisplayStatus: only Execute writes Status, so a
30			// stored proposal is Open until Executed and this is exactly
31			// "not yet executed". Computing the display status here would
32			// evaluate every proposal's condition a second time — the table
33			// below already does it for the ones that survive the filter.
34			return p.Status == daokit.ProposalStatusOpen || p.Status == daokit.ProposalStatusPassed
35		},
36	)
37	s := ""
38	s += ufmt.Sprintf("## Active Proposals 🗳️ (%d)\n\n", activeProposals.Tree.Size())
39	s += d.RenderProposalsTable(path, activeProposals)
40	s += ufmt.Sprintf("\n--------------------------------\n")
41	return s
42}