From 2dc9835913b24cb45606e1d0d9fa96a6d921cae9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa?= Date: Tue, 18 Sep 2018 15:43:28 +0200 Subject: [PATCH] WIP custom homepage --- app/coffee/app.coffee | 11 ++++ app/coffee/modules/base.coffee | 1 + app/coffee/modules/common/sections.coffee | 43 ++++++++++++ app/coffee/modules/resources.coffee | 4 ++ .../resources/user-project-settings.coffee | 36 ++++++++++ .../user-project-settings.coffee | 65 +++++++++++++++++++ app/locales/taiga/locale-en.json | 6 ++ .../project/project-router.controller.coffee | 55 ++++++++++++++++ .../includes/modules/user-settings-menu.jade | 3 + app/partials/user/user-project-settings.jade | 37 +++++++++++ .../user-settings/project-settings-table.scss | 28 ++++++++ 11 files changed, 289 insertions(+) create mode 100644 app/coffee/modules/common/sections.coffee create mode 100644 app/coffee/modules/resources/user-project-settings.coffee create mode 100644 app/coffee/modules/user-settings/user-project-settings.coffee create mode 100644 app/modules/projects/project/project-router.controller.coffee create mode 100644 app/partials/user/user-project-settings.jade create mode 100644 app/styles/modules/user-settings/project-settings-table.scss diff --git a/app/coffee/app.coffee b/app/coffee/app.coffee index 2b5030ac..85f41dc1 100644 --- a/app/coffee/app.coffee +++ b/app/coffee/app.coffee @@ -172,6 +172,15 @@ configure = ($routeProvider, $locationProvider, $httpProvider, $provide, $tgEven # Project $routeProvider.when("/project/:pslug/", + { + template: "", + loader: true, + controller: "ProjectRouter" + } + ) + + # Project + $routeProvider.when("/project/:pslug/timeline", { templateUrl: "projects/project/project.html", loader: true, @@ -450,6 +459,8 @@ configure = ($routeProvider, $locationProvider, $httpProvider, $provide, $tgEven {templateUrl: "user/user-profile.html"}) $routeProvider.when("/user-settings/user-change-password", {templateUrl: "user/user-change-password.html"}) + $routeProvider.when("/user-settings/user-project-settings", + {templateUrl: "user/user-project-settings.html"}) $routeProvider.when("/user-settings/mail-notifications", {templateUrl: "user/mail-notifications.html"}) $routeProvider.when("/user-settings/live-notifications", diff --git a/app/coffee/modules/base.coffee b/app/coffee/modules/base.coffee index 0d06ba74..203b3ccc 100644 --- a/app/coffee/modules/base.coffee +++ b/app/coffee/modules/base.coffee @@ -119,6 +119,7 @@ urls = { "user-settings-user-profile": "/user-settings/user-profile" "user-settings-user-change-password": "/user-settings/user-change-password" "user-settings-user-avatar": "/user-settings/user-avatar" + "user-settings-user-project-settings": "/user-settings/user-project-settings" "user-settings-mail-notifications": "/user-settings/mail-notifications" "user-settings-live-notifications": "/user-settings/live-notifications" "user-settings-contrib": "/user-settings/contrib/:plugin" diff --git a/app/coffee/modules/common/sections.coffee b/app/coffee/modules/common/sections.coffee new file mode 100644 index 00000000..67e1a41d --- /dev/null +++ b/app/coffee/modules/common/sections.coffee @@ -0,0 +1,43 @@ +### +# Copyright (C) 2014-2017 Andrey Antukh +# Copyright (C) 2014-2017 Jesús Espino Garcia +# Copyright (C) 2014-2017 David Barragán Merino +# Copyright (C) 2014-2017 Alejandro Alonso +# Copyright (C) 2014-2017 Juan Francisco Alcántara +# Copyright (C) 2014-2017 Xavi Julian +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +# File: modules/common/sections.coffee +### + +module = angular.module("taigaCommon") + +SECTIONS = { + 1: {id: 1, title: 'TIMELINE', path:'timeline'} + 2: {id: 2, title: 'SEARCH', path:'search'} + 3: {id: 3, title: 'BACKLOG', path:'backlog'} + 4: {id: 4, title: 'KANBAN', path:'kanban'} + 5: {id: 5, title: 'ISSUES', path:'issues'} + 6: {id: 6, title: 'WIKI', path:'wiki'} + 7: {id: 7, title: 'TEAM', path:'team'} + 8: {id: 8, title: 'MEETUP', path:'meetup'} + 9: {id: 9, title: 'ADMIN', path:'admin'} +} + +class SectionsService extends taiga.Service + list: () -> + return SECTIONS + +module.service("$tgSections", SectionsService) diff --git a/app/coffee/modules/resources.coffee b/app/coffee/modules/resources.coffee index 6ea2affd..694915f9 100644 --- a/app/coffee/modules/resources.coffee +++ b/app/coffee/modules/resources.coffee @@ -47,6 +47,9 @@ urls = { "permissions": "/permissions" "notify-policies": "/notify-policies" + # User Project Settings + "user-project-settings": "/user-project-settings" + # User - Storage "user-storage": "/user-storage" @@ -261,6 +264,7 @@ module.run([ "$tgNotifyPoliciesResourcesProvider", "$tgInvitationsResourcesProvider", "$tgRolesResourcesProvider", + "$tgUserProjectSettingsResourcesProvider", "$tgUserSettingsResourcesProvider", "$tgSprintsResourcesProvider", "$tgEpicsResourcesProvider", diff --git a/app/coffee/modules/resources/user-project-settings.coffee b/app/coffee/modules/resources/user-project-settings.coffee new file mode 100644 index 00000000..6217cef6 --- /dev/null +++ b/app/coffee/modules/resources/user-project-settings.coffee @@ -0,0 +1,36 @@ +### +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +# File: modules/resources/user-project-settings.coffee +### + +taiga = @.taiga + +resourceProvider = ($repo, $http, $urls) -> + service = {} + + service.get = (id) -> + return $repo.queryOne("user-project-settings", id) + + service.list = (filters) -> + params = _.extend({}, params, filters or {}) + return $repo.queryMany("user-project-settings", params) + + return (instance) -> + instance.userProjectSettings = service + + +module = angular.module("taigaResources") +module.factory("$tgUserProjectSettingsResourcesProvider", ["$tgRepo", "$tgHttp", "$tgUrls", resourceProvider]) diff --git a/app/coffee/modules/user-settings/user-project-settings.coffee b/app/coffee/modules/user-settings/user-project-settings.coffee new file mode 100644 index 00000000..6c6953ab --- /dev/null +++ b/app/coffee/modules/user-settings/user-project-settings.coffee @@ -0,0 +1,65 @@ +### +# Copyright (C) 2014-2017 Andrey Antukh +# Copyright (C) 2014-2017 Jesús Espino Garcia +# Copyright (C) 2014-2017 David Barragán Merino +# Copyright (C) 2014-2017 Alejandro Alonso +# Copyright (C) 2014-2017 Juan Francisco Alcántara +# Copyright (C) 2014-2017 Xavi Julian +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +# File: modules/user-settings/user-project-settings.coffee +### + +taiga = @.taiga +mixOf = @.taiga.mixOf +bindOnce = @.taiga.bindOnce + +module = angular.module("taigaUserSettings") + + +############################################################################# +## Custom Homepage Controller +############################################################################# + +class UserProjectSettingsController extends mixOf(taiga.Controller, taiga.PageMixin) + @.$inject = [ + "$scope" + "$tgSections" + "$tgResources" + "$tgRepo" + "$tgConfirm" + ] + + constructor: (@scope, @tgSections, @rs, @repo, @confirm) -> + promise = @.loadInitialData() + promise.then null, @.onInitialDataError.bind(@) + @scope.sections = @tgSections.list() + + loadInitialData: -> + return @rs.userProjectSettings.list().then (userProjectSettings) => + @scope.userProjectSettings = userProjectSettings + return userProjectSettings + + updateCustomHomePage: (project, customHomePage) -> + onSuccess = => + @confirm.notify("success") + + onError = => + @confirm.notify("error") + + # @repo.save(project).then(onSuccess, onError) + + +module.controller("UserProjectSettingsController", UserProjectSettingsController) diff --git a/app/locales/taiga/locale-en.json b/app/locales/taiga/locale-en.json index 789bb08a..5b8d350b 100644 --- a/app/locales/taiga/locale-en.json +++ b/app/locales/taiga/locale-en.json @@ -1561,6 +1561,12 @@ "OPTION_ALL": "All", "OPTION_INVOLVED": "Involved", "OPTION_NONE": "None" + }, + "PROJECT_SETTINGS": { + "CUSTOM_HOMEPAGE": "Custom Homepage", + "COLUMN_PROJECT": "Project", + "COLUMN_HOMEPAGE": "Homepage", + "DEFAULT_VALUE": "Default" } }, "USER_PROFILE": { diff --git a/app/modules/projects/project/project-router.controller.coffee b/app/modules/projects/project/project-router.controller.coffee new file mode 100644 index 00000000..3e7d3455 --- /dev/null +++ b/app/modules/projects/project/project-router.controller.coffee @@ -0,0 +1,55 @@ +### +# Copyright (C) 2014-2017 Taiga Agile LLC +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +# File: project-router.controller.coffee +### + +class ProjectRouterController + @.$inject = [ + "$routeParams", + "$location" + "tgProjectService" + "$tgResources" + "$tgSections" + ] + + constructor: (@routeParams, @location, @projectService, @rs, @tgSections) -> + @getProjectHomepage() + .then (section) => + if section + @location.url("project/#{@routeParams.pslug}/#{section}") + else + gotoDefaultProjectHomepage() + .then null, -> + gotoDefaultProjectHomepage() + + gotoDefaultProjectHomepage: () -> + @location.url("project/#{@routeParams.pslug}/timeline") + + getProjectHomepage: () -> + sections = @tgSections.list() + project = @projectService.project.toJS() + + @rs.userProjectSettings.list().then (userProjectSettings) -> + settings = _.find(userProjectSettings, {"project": project.id}) + return if !settings + + section = _.find(sections, {"id": settings.homepage}) + return if !section + + return section.path + +angular.module("taigaProjects").controller("ProjectRouter", ProjectRouterController) diff --git a/app/partials/includes/modules/user-settings-menu.jade b/app/partials/includes/modules/user-settings-menu.jade index 070e6ac2..47e07ef6 100644 --- a/app/partials/includes/modules/user-settings-menu.jade +++ b/app/partials/includes/modules/user-settings-menu.jade @@ -7,6 +7,9 @@ section.admin-menu li#usersettingsmenu-change-password a(href="" tg-nav="user-settings-user-change-password", title="{{ 'USER_SETTINGS.MENU.CHANGE_PASSWORD' | translate }}") span.title(translate="USER_SETTINGS.MENU.CHANGE_PASSWORD") + li#usersettingsmenu-custom-homepage + a(href="", tg-nav="user-settings-user-project-settings", title="{{ 'USER_SETTINGS.PROJECT_SETTINGS.CUSTOM_HOMEPAGE' | translate }}") + span.title(translate="USER_SETTINGS.PROJECT_SETTINGS.CUSTOM_HOMEPAGE") li#usersettingsmenu-mail-notifications a(href="", tg-nav="user-settings-mail-notifications", title="{{ 'USER_SETTINGS.MENU.EMAIL_NOTIFICATIONS' | translate }}") span.title(translate="USER_SETTINGS.MENU.EMAIL_NOTIFICATIONS") diff --git a/app/partials/user/user-project-settings.jade b/app/partials/user/user-project-settings.jade new file mode 100644 index 00000000..2a9946f5 --- /dev/null +++ b/app/partials/user/user-project-settings.jade @@ -0,0 +1,37 @@ +doctype html + +div.wrapper( + ng-controller="UserProjectSettingsController as ctrl", + ng-init="section='project-settings'" +) + + sidebar.menu-secondary.sidebar.settings-nav(tg-user-settings-navigation="project-settings") + include ../includes/modules/user-settings-menu + + section.main.admin-common + header + h1 + span.green {{ 'USER_SETTINGS.PROJECT_SETTINGS.CUSTOM_HOMEPAGE' | translate }} + + section.project-settings-table + div.custom-table-header + div.project-settings-table-row + div.project-settings-table-project + span(translate="USER_SETTINGS.PROJECT_SETTINGS.COLUMN_PROJECT") + div.project-settings-table-homepage + span(translate="USER_SETTINGS.PROJECT_SETTINGS.COLUMN_HOMEPAGE") + div.project-settings-table-body + .project-settings-table-row(ng-repeat="projectSettings in userProjectSettings") + .project-settings-table-project + span {{ projectSettings.project_name }} + .project-settings-table-homepage + select( + id="projects-settings-{{projectSettings.id}}-homepage-dropdown" + ) + option( + ng-value="null" + ) {{ 'USER_SETTINGS.PROJECT_SETTINGS.DEFAULT_VALUE' | translate }} + option( + ng-repeat="section in sections" + value="{{ section.id }}" + ) {{ 'PROJECT.SECTION.' + section.title | translate }} \ No newline at end of file diff --git a/app/styles/modules/user-settings/project-settings-table.scss b/app/styles/modules/user-settings/project-settings-table.scss new file mode 100644 index 00000000..a393dc20 --- /dev/null +++ b/app/styles/modules/user-settings/project-settings-table.scss @@ -0,0 +1,28 @@ +.project-settings-table { + .project-settings-table-row { + align-items: center; + border-bottom: 1px solid $whitish; + display: flex; + justify-content: center; + } + + .project-settings-table-header { + @include font-type(bold); + border-bottom: 2px solid $gray-light; + } + + .project-settings-table-project , + .project-settings-table-homepage { + padding: 1rem; + } + + .project-settings-table-project { + flex-basis: 0; + flex-grow: 3; + } + + .project-settings-table-homepage { + flex-basis: 0; + flex-grow: 1; + } +}