From d304bbeb5e159e6dae19953b6c1ee9a83a48e020 Mon Sep 17 00:00:00 2001 From: Benjamin ter Kuile Date: Mon, 30 Jul 2018 11:50:10 +0200 Subject: [PATCH] User statistics updates --- .../action-list/organization-filter.coffee | 6 +++++ .../action-list/organization-filter.js | 9 +++++++ .../organization-statistics1.coffee | 3 ++- addon/components/organization-statistics1.js | 4 ++- addon/components/user-main-statistics1.coffee | 6 +++-- addon/components/user-main-statistics1.js | 6 +++-- addon/routes/action-list.coffee | 17 +++++++------ addon/routes/action-list.js | 10 ++++++-- addon/styles/components/_state-badge.sass | 3 +++ .../show/project-instance-action/index.coffee | 3 ++- .../show/project-instance-action/index.coffee | 17 +++++++------ .../show/project-instance-group/index.coffee | 4 +-- .../organization-statistics1.emblem | 25 ++++++++++++++----- .../components/user-main-statistics1.emblem | 25 ++++++++++++++----- .../show/project-instance-action/index.emblem | 3 +++ 15 files changed, 103 insertions(+), 38 deletions(-) diff --git a/addon/components/action-list/organization-filter.coffee b/addon/components/action-list/organization-filter.coffee index 2ced11f..5199aee 100644 --- a/addon/components/action-list/organization-filter.coffee +++ b/addon/components/action-list/organization-filter.coffee @@ -29,3 +29,9 @@ export default Ember.Component.extend 'filters.workflow_action_definition_organization_id': '' @$('.select-organization .dropdown.button').removeClass('orange') @send 'apply_filters' + didRender: -> + if organization_id = @get('filters.workflow_action_definition_organization_id') + if organization = @get('relevant_organizations').findBy('id', organization_id) + @set 'scope_organization', organization + @$('.select-organization .dropdown.button').addClass('orange') + diff --git a/addon/components/action-list/organization-filter.js b/addon/components/action-list/organization-filter.js index 2b6259a..618eeba 100644 --- a/addon/components/action-list/organization-filter.js +++ b/addon/components/action-list/organization-filter.js @@ -46,5 +46,14 @@ export default Ember.Component.extend({ return this.send('apply_filters'); } } + }, + didRender: function() { + var organization, organization_id; + if (organization_id = this.get('filters.workflow_action_definition_organization_id')) { + if (organization = this.get('relevant_organizations').findBy('id', organization_id)) { + this.set('scope_organization', organization); + return this.$('.select-organization .dropdown.button').addClass('orange'); + } + } } }); diff --git a/addon/components/organization-statistics1.coffee b/addon/components/organization-statistics1.coffee index 2b2dde8..09b824e 100644 --- a/addon/components/organization-statistics1.coffee +++ b/addon/components/organization-statistics1.coffee @@ -5,6 +5,7 @@ export default Ember.Component.extend record: null # parameter project_specific: false # parameter session: Ember.inject.service('session') + classNames: ['project-aggregate-statistics', 'project-aggregate-organization-statistics'] statistics: Ember.computed 'statistics_data.isFulfilled', 'project_specific', -> d = @get('statistics_data') return {} unless d.isFulfilled @@ -21,7 +22,7 @@ export default Ember.Component.extend project_name = project.get('name') target[project_name] = [] states.forEach (state) -> - target[project_name].push(state: state, count: stats[state] || 0) + target[project_name].push(state: state, count: stats[state] || 0, project_id: project_id) else for state, count of stats target[state] += count diff --git a/addon/components/organization-statistics1.js b/addon/components/organization-statistics1.js index 75dae35..f3beb1e 100644 --- a/addon/components/organization-statistics1.js +++ b/addon/components/organization-statistics1.js @@ -7,6 +7,7 @@ export default Ember.Component.extend({ record: null, project_specific: false, session: Ember.inject.service('session'), + classNames: ['project-aggregate-statistics', 'project-aggregate-organization-statistics'], statistics: Ember.computed('statistics_data.isFulfilled', 'project_specific', function() { var count, d, global_name, project, project_id, project_name, project_specific, ref, state, states, stats, target; d = this.get('statistics_data'); @@ -32,7 +33,8 @@ export default Ember.Component.extend({ states.forEach(function(state) { return target[project_name].push({ state: state, - count: stats[state] || 0 + count: stats[state] || 0, + project_id: project_id }); }); } else { diff --git a/addon/components/user-main-statistics1.coffee b/addon/components/user-main-statistics1.coffee index 7a1166c..b65f9d3 100644 --- a/addon/components/user-main-statistics1.coffee +++ b/addon/components/user-main-statistics1.coffee @@ -5,11 +5,13 @@ export default Ember.Component.extend user: null # parameter project_specific: false # parameter session: Ember.inject.service('session') + classNames: ['project-aggregate-statistics', 'project-aggregate-user-statistics'] statistics: Ember.computed 'statistics_data.isFulfilled', 'project_specific', -> d = @get('statistics_data') return {} unless d.isFulfilled target = {} - states = ['pending', 'planned', 'active', 'overdue', 'inquiry', 'rejected', 'completed'] + #states = ['pending', 'planned', 'active', 'overdue', 'inquiry', 'rejected', 'completed'] + states = @get('globals.project_instance_action.states') project_specific = @get('project_specific') unless project_specific global_name = t('user.statistics1.global.title') @@ -21,7 +23,7 @@ export default Ember.Component.extend project_name = project.get('name') target[project_name] = [] states.forEach (state) -> - target[project_name].push(state: state, count: stats[state] || 0) + target[project_name].push(state: state, count: stats[state] || 0, project_id: project_id) else for state, count of stats target[state] += count diff --git a/addon/components/user-main-statistics1.js b/addon/components/user-main-statistics1.js index 3c4ad8e..84124ee 100644 --- a/addon/components/user-main-statistics1.js +++ b/addon/components/user-main-statistics1.js @@ -7,6 +7,7 @@ export default Ember.Component.extend({ user: null, project_specific: false, session: Ember.inject.service('session'), + classNames: ['project-aggregate-statistics', 'project-aggregate-user-statistics'], statistics: Ember.computed('statistics_data.isFulfilled', 'project_specific', function() { var count, d, global_name, project, project_id, project_name, project_specific, ref, state, states, stats, target; d = this.get('statistics_data'); @@ -14,7 +15,7 @@ export default Ember.Component.extend({ return {}; } target = {}; - states = ['pending', 'planned', 'active', 'overdue', 'inquiry', 'rejected', 'completed']; + states = this.get('globals.project_instance_action.states'); project_specific = this.get('project_specific'); if (!project_specific) { global_name = t('user.statistics1.global.title'); @@ -32,7 +33,8 @@ export default Ember.Component.extend({ states.forEach(function(state) { return target[project_name].push({ state: state, - count: stats[state] || 0 + count: stats[state] || 0, + project_id: project_id }); }); } else { diff --git a/addon/routes/action-list.coffee b/addon/routes/action-list.coffee index 00f92d3..0ca8d21 100644 --- a/addon/routes/action-list.coffee +++ b/addon/routes/action-list.coffee @@ -19,11 +19,12 @@ export filters = Ember.Object.create export default Ember.Route.extend queryParams: - state: {refreshModel: true} - project: {refreshModel: true} - action: {refreshModel: true} - page: {refreshModel: true} - perPage: {refreshModel: true} + state: {refreshModel: true} + project: {refreshModel: true} + action: {refreshModel: true} + page: {refreshModel: true} + perPage: {refreshModel: true} + organization_id: {refreshModel: true} modelName: 'panda/project-instance-action' setupController: (controller) -> controller.set 'filters', filters @@ -53,8 +54,9 @@ export default Ember.Route.extend # 'pointing_project_instance_action_connections.project_instance_action.workflow_action_definition.~organization' # 'pointing_project_instance_action_connections.project_instance_action.workflow_action_definition.~workflow_action_offsets' #] - filters.state_in = [params.state] if params.state - filters.workflow_action_definition_identifier_in = [params.action] if params.action + filters.set('state_in', params.state.split(',')) if params.state + filters.set('workflow_action_definition_identifier_in', params.action.split(',')) if params.action + filters.set('workflow_action_definition_organization_id', params.organization_id) if params.organization_id Ember.RSVP.hash projects: @store.findAll('panda/project') organizations: @store.findAll('panda/organization') @@ -66,5 +68,4 @@ export default Ember.Route.extend page: params.page || 1 perPage: params.perPage || 30 otherParams: - #include: includes.join(',') include: 'action-list' diff --git a/addon/routes/action-list.js b/addon/routes/action-list.js index 4784477..929de8e 100644 --- a/addon/routes/action-list.js +++ b/addon/routes/action-list.js @@ -35,6 +35,9 @@ export default Ember.Route.extend({ }, perPage: { refreshModel: true + }, + organization_id: { + refreshModel: true } }, modelName: 'panda/project-instance-action', @@ -44,10 +47,13 @@ export default Ember.Route.extend({ }, model: function(params) { if (params.state) { - filters.state_in = [params.state]; + filters.set('state_in', params.state.split(',')); } if (params.action) { - filters.workflow_action_definition_identifier_in = [params.action]; + filters.set('workflow_action_definition_identifier_in', params.action.split(',')); + } + if (params.organization_id) { + filters.set('workflow_action_definition_organization_id', params.organization_id); } return Ember.RSVP.hash({ projects: this.store.findAll('panda/project'), diff --git a/addon/styles/components/_state-badge.sass b/addon/styles/components/_state-badge.sass index 5d216ca..4300546 100644 --- a/addon/styles/components/_state-badge.sass +++ b/addon/styles/components/_state-badge.sass @@ -1,3 +1,6 @@ .state-badge &.with-action cursor: pointer +.project-aggregate-statistics + .ui.label.state-badge + margin-right: 4px diff --git a/app/controllers/project/show/project-instance-action/index.coffee b/app/controllers/project/show/project-instance-action/index.coffee index 7d47951..50dea9b 100644 --- a/app/controllers/project/show/project-instance-action/index.coffee +++ b/app/controllers/project/show/project-instance-action/index.coffee @@ -2,7 +2,8 @@ import Ember from 'ember' import {create_date_sort} from 'ember-cli-dunlop/utils/date-sort' date_sort = create_date_sort('date') export default Ember.Controller.extend - queryParams: ['state'] + organizations: ( -> @store.peekAll('panda/organization')).property() + queryParams: ['state', 'organization_id'] #filter: Ember.Object.create # workflow_action_definition_id_in: [] # project_instance_group_workflow_group_id_in: [] diff --git a/app/routes/project/show/project-instance-action/index.coffee b/app/routes/project/show/project-instance-action/index.coffee index 17b436a..4a82c7a 100644 --- a/app/routes/project/show/project-instance-action/index.coffee +++ b/app/routes/project/show/project-instance-action/index.coffee @@ -2,6 +2,7 @@ import Ember from 'ember' import PagedRemoteArray from 'ember-cli-dunlop/utils/paged-remote-array' export filters = Ember.Object.create workflow_action_definition_id_in: [] + workflow_action_definition_organization_id_eq: '' project_instance_group_workflow_group_id: '' state_in: [] target_date_gteq: null @@ -11,9 +12,10 @@ export filters = Ember.Object.create export default Ember.Route.extend modelName: 'panda/project-instance-action' queryParams: - state: {refreshModel: true} - page: {refreshModel: true} - perPage: {refreshModel: true} + state: {refreshModel: true} + organization_id: {refreshModel: true} + page: {refreshModel: true} + perPage: {refreshModel: true} setupController: (controller, model) -> controller.set 'filters', filters controller.set 'project', @modelFor('project.show') @@ -21,13 +23,14 @@ export default Ember.Route.extend model: (params) -> project = @modelFor 'project.show' - filters.project_id = project.id - includes = 'action-list' - filters.state_in = [params.state] if params.state + filters.set('project_id', project.id) + filters.set('state_in', params.state.split(',')) if params.state + filters.set('workflow_action_definition_organization_id_eq', params.organization_id) if params.organization_id PagedRemoteArray.create modelName: @modelName store: @store filters: filters page: params.page || 1 perPage: params.perPage || 30 - otherParams: {includes: includes} + otherParams: + include: 'action-list' diff --git a/app/routes/project/show/project-instance-group/index.coffee b/app/routes/project/show/project-instance-group/index.coffee index 71ae001..99ec801 100644 --- a/app/routes/project/show/project-instance-group/index.coffee +++ b/app/routes/project/show/project-instance-group/index.coffee @@ -18,8 +18,8 @@ export default Ember.Route.extend model: (params) -> project = @modelFor 'project.show' - filters.project_id = project.id - filters.state_in = [params.state] if params.state + filters.set('project_id', project.id) + filters.set('state_in', params.state.split(',')) if params.state PagedRemoteArray.create modelName: @modelName store: @store diff --git a/app/templates/components/organization-statistics1.emblem b/app/templates/components/organization-statistics1.emblem index e4aa3cf..5452dba 100644 --- a/app/templates/components/organization-statistics1.emblem +++ b/app/templates/components/organization-statistics1.emblem @@ -1,18 +1,31 @@ if statistics ui-checkbox class='toggle' label=(t 'user.statistics1.project_specific.label') checked=project_specific onChange=(action (mut project_specific)) + ' if project_specific each-in statistics as |project_name stats| .ui.header= project_name = each stats as |stat| - = state-badge stat.state - ' - span.between-brackets= stat.count + if (can 'read' 'model' 'panda/project-instance') + = link-to 'project.show.project-instance-action' stat.project_id (query-params state=stat.state organization_id=record.id) + = state-badge stat.state + ' + span.between-brackets= stat.count + else + = state-badge stat.state + ' + span.between-brackets= stat.count else /.ui.header= t 'user.statistics1.global.title' each-in statistics as |state count| - = state-badge state - ' - span.between-brackets= count + if (can 'read' 'model' 'panda/project-instance') + = link-to 'action-list' (query-params state=state organization_id=record.id) + = state-badge state + ' + span.between-brackets= count + else + = state-badge state + ' + span.between-brackets= count = yield else .ui.active.inline.centered.loader diff --git a/app/templates/components/user-main-statistics1.emblem b/app/templates/components/user-main-statistics1.emblem index dfe130c..8cc8e8e 100644 --- a/app/templates/components/user-main-statistics1.emblem +++ b/app/templates/components/user-main-statistics1.emblem @@ -3,19 +3,32 @@ if user.email span.ui.segment.pull-right= user.nickname if statistics ui-checkbox class='toggle' label=(t 'user.statistics1.project_specific.label') checked=project_specific onChange=(action (mut project_specific)) + ' if project_specific each-in statistics as |project_name stats| .ui.header= project_name = each stats as |stat| - = state-badge stat.state - ' - span.between-brackets= stat.count + if (can 'read' 'model' 'panda/project-instance') + = link-to 'project.show.project-instance-action' stat.project_id (query-params state=stat.state) + = state-badge stat.state + ' + span.between-brackets= stat.count + else + = state-badge stat.state + ' + span.between-brackets= stat.count else /.ui.header= t 'user.statistics1.global.title' each-in statistics as |state count| - = state-badge state - ' - span.between-brackets= count + if (can 'read' 'model' 'panda/project-instance') + = link-to 'action-list' (query-params state=state) + = state-badge state + ' + span.between-brackets= count + else + = state-badge state + ' + span.between-brackets= count = yield else .ui.active.inline.centered.loader diff --git a/app/templates/project/show/project-instance-action/index.emblem b/app/templates/project/show/project-instance-action/index.emblem index c5e9552..05cc615 100644 --- a/app/templates/project/show/project-instance-action/index.emblem +++ b/app/templates/project/show/project-instance-action/index.emblem @@ -21,6 +21,7 @@ d-breadcrumbs as |breadcrumb| table.ui.bottom.attached.stiped.table thead tr + th= t 'models.organization' th= t 'models.project_instance_group' th= t 'models.workflow_action_definition' th= t 'models.project_instance' @@ -35,6 +36,7 @@ table.ui.bottom.attached.stiped.table th= t 'attributes.project_instance_action.target_date' th= t 'attributes.project_instance_action.value' table-filters content=model filters=filters as |filter| + = filter.dropdown-select key='workflow_action_definition_organization_id_eq' options=organizations labelPath='name' = filter.dropdown-select key='project_instance_group_workflow_group_id' options=project.sorted_workflow_groups labelPath='name' / ui-dropdown class='right basic labeled icon' action='nothing' i.dropdown.icon @@ -84,6 +86,7 @@ table.ui.bottom.attached.stiped.table tbody each filtered_project_instance_actions as |project_instance_action| tr + td= project_instance_action.workflow_action_definition.organization.name td if project_instance_action.project_instance_group.id = link-to 'project.show.project-instance-group.show' project_instance_action.project_instance.project.id project_instance_action.project_instance_group.id