Skip to content

Commit

Permalink
feat: also order projects by name
Browse files Browse the repository at this point in the history
Closes mujx#79.
  • Loading branch information
williamboman committed May 2, 2023
1 parent cdb5323 commit 2e7164f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
6 changes: 3 additions & 3 deletions dashboard/src/components/projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ const ProjectComponent = {
const toolbar = m("div.d-sm-flex.mb-4", [
m(
"h1.h3.mb-0.mr-auto.text-gray-800",
LocalState.currentProject ? LocalState.currentProject : "Projects"
LocalState.currentProject ? LocalState.currentProject.name : "Projects"
),
m("div.autoComplete_wrapper", [
m(
Expand All @@ -546,9 +546,9 @@ const ProjectComponent = {
return m(
"a.btn.dropdown-item",
{
onclick: LocalState.fetchProjectStats
onclick: () => { LocalState.fetchProjectStats(project) }
},
project
project.name
);
})
)
Expand Down
14 changes: 13 additions & 1 deletion dashboard/src/models/ProjectState.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,17 @@ import utils from "../utils.js";
import * as auth from "../auth";
import * as api from "../api";

/**
* @typedef {Object} Project
* @property {string} name
* @property {string} desc
* @property {number} totalSeconds
*/

const Model = {
/** @type {Project[]} */
projects: [],
/** @type {Project?} */
currentProject: null,
dates: null,
obj: null,
Expand All @@ -14,8 +23,11 @@ const Model = {
Model.dates = null;
Model.obj = null;
},
/** @param {Project[]} projects */
initProjectList: projects => {
Model.projects = projects;
Model.projects = _.orderBy(projects, ["totalSeconds", "name"], ["desc", "asc"])
.filter(n => n.name !== "Other")
.sort((a, b) => a.name.localeCompare(b.name));

if (Model.projects.length > 0) {
Model.currentProject = Model.projects[0];
Expand Down

0 comments on commit 2e7164f

Please sign in to comment.