Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: also order projects by name #80

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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