diff --git a/addon/components/organization-statistics1.coffee b/addon/components/organization-statistics1.coffee new file mode 100644 index 0000000..2b2dde8 --- /dev/null +++ b/addon/components/organization-statistics1.coffee @@ -0,0 +1,55 @@ +import Ember from 'ember' +import DS from 'ember-data' + +export default Ember.Component.extend + record: null # parameter + project_specific: false # parameter + session: Ember.inject.service('session') + 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'] + project_specific = @get('project_specific') + unless project_specific + global_name = t('organization.statistics1.global.title') + states.forEach (state) -> + target[state] = 0 + for project_id, stats of d.content.data + if project_specific + project = d.content.projects.findBy('id', project_id) + project_name = project.get('name') + target[project_name] = [] + states.forEach (state) -> + target[project_name].push(state: state, count: stats[state] || 0) + else + for state, count of stats + target[state] += count + + #if project_object.project and project_object.project.id isnt project.id + # target.push project_object + # project_object = {project: project} + # continue + #project_object.project = project + + target + + statistics_data: Ember.computed -> + return {} unless record_id = @get('record.id') + model_name = 'panda/organization' + base_url = @store.adapterFor(model_name).buildURL(model_name) + url = "#{base_url}/#{record_id}/statistics1" + session = @get('session') + store = @store + request = + url: url + contentType: "application/json" + dataType: "json" + #success: (response) -> + # resolve(response) + if Ember.get(session, 'isAuthenticated') + session.authorize 'authorizer:devise', (key, authorization) -> + request.crossDomain = true + request.headers = {"#{key}": authorization} + DS.PromiseObject.create + promise: Ember.RSVP.hash(data: Ember.$.ajax(request), projects: store.findAll('panda/project', backgroundReload: false)) diff --git a/addon/components/organization-statistics1.js b/addon/components/organization-statistics1.js new file mode 100644 index 0000000..75dae35 --- /dev/null +++ b/addon/components/organization-statistics1.js @@ -0,0 +1,82 @@ +// Generated by CoffeeScript 1.12.5 +import Ember from 'ember'; + +import DS from 'ember-data'; + +export default Ember.Component.extend({ + record: null, + project_specific: false, + session: Ember.inject.service('session'), + 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'); + if (!d.isFulfilled) { + return {}; + } + target = {}; + states = ['pending', 'planned', 'active', 'overdue', 'inquiry', 'rejected', 'completed']; + project_specific = this.get('project_specific'); + if (!project_specific) { + global_name = t('organization.statistics1.global.title'); + states.forEach(function(state) { + return target[state] = 0; + }); + } + ref = d.content.data; + for (project_id in ref) { + stats = ref[project_id]; + if (project_specific) { + project = d.content.projects.findBy('id', project_id); + project_name = project.get('name'); + target[project_name] = []; + states.forEach(function(state) { + return target[project_name].push({ + state: state, + count: stats[state] || 0 + }); + }); + } else { + for (state in stats) { + count = stats[state]; + target[state] += count; + } + } + } + return target; + }), + statistics_data: Ember.computed(function() { + var base_url, model_name, record_id, request, session, store, url; + if (!(record_id = this.get('record.id'))) { + return {}; + } + model_name = 'panda/organization'; + base_url = this.store.adapterFor(model_name).buildURL(model_name); + url = base_url + "/" + record_id + "/statistics1"; + session = this.get('session'); + store = this.store; + request = { + url: url, + contentType: "application/json", + dataType: "json" + }; + if (Ember.get(session, 'isAuthenticated')) { + session.authorize('authorizer:devise', function(key, authorization) { + var obj; + request.crossDomain = true; + return request.headers = ( + obj = {}, + obj["" + key] = authorization, + obj + ); + }); + } + return DS.PromiseObject.create({ + promise: Ember.RSVP.hash({ + data: Ember.$.ajax(request), + projects: store.findAll('panda/project', { + backgroundReload: false + }) + }) + }); + }) +}); diff --git a/addon/components/user-main-statistics1.coffee b/addon/components/user-main-statistics1.coffee new file mode 100644 index 0000000..7a1166c --- /dev/null +++ b/addon/components/user-main-statistics1.coffee @@ -0,0 +1,54 @@ +import Ember from 'ember' +import DS from 'ember-data' + +export default Ember.Component.extend + user: null # parameter + project_specific: false # parameter + session: Ember.inject.service('session') + 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'] + project_specific = @get('project_specific') + unless project_specific + global_name = t('user.statistics1.global.title') + states.forEach (state) -> + target[state] = 0 + for project_id, stats of d.content.data + if project_specific + project = d.content.projects.findBy('id', project_id) + project_name = project.get('name') + target[project_name] = [] + states.forEach (state) -> + target[project_name].push(state: state, count: stats[state] || 0) + else + for state, count of stats + target[state] += count + + #if project_object.project and project_object.project.id isnt project.id + # target.push project_object + # project_object = {project: project} + # continue + #project_object.project = project + + target + statistics_data: Ember.computed -> + return {} unless user_id = @get('user.id') + model_name = 'user' + base_url = @store.adapterFor(model_name).buildURL(model_name) + url = "#{base_url}/#{user_id}/statistics1" + session = @get('session') + store = @store + request = + url: url + contentType: "application/json" + dataType: "json" + #success: (response) -> + # resolve(response) + if Ember.get(session, 'isAuthenticated') + session.authorize 'authorizer:devise', (key, authorization) -> + request.crossDomain = true + request.headers = {"#{key}": authorization} + DS.PromiseObject.create + promise: Ember.RSVP.hash(data: Ember.$.ajax(request), projects: store.findAll('panda/project', backgroundReload: false)) diff --git a/addon/components/user-main-statistics1.js b/addon/components/user-main-statistics1.js new file mode 100644 index 0000000..3c4ad8e --- /dev/null +++ b/addon/components/user-main-statistics1.js @@ -0,0 +1,82 @@ +// Generated by CoffeeScript 1.12.5 +import Ember from 'ember'; + +import DS from 'ember-data'; + +export default Ember.Component.extend({ + user: null, + project_specific: false, + session: Ember.inject.service('session'), + 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'); + if (!d.isFulfilled) { + return {}; + } + target = {}; + states = ['pending', 'planned', 'active', 'overdue', 'inquiry', 'rejected', 'completed']; + project_specific = this.get('project_specific'); + if (!project_specific) { + global_name = t('user.statistics1.global.title'); + states.forEach(function(state) { + return target[state] = 0; + }); + } + ref = d.content.data; + for (project_id in ref) { + stats = ref[project_id]; + if (project_specific) { + project = d.content.projects.findBy('id', project_id); + project_name = project.get('name'); + target[project_name] = []; + states.forEach(function(state) { + return target[project_name].push({ + state: state, + count: stats[state] || 0 + }); + }); + } else { + for (state in stats) { + count = stats[state]; + target[state] += count; + } + } + } + return target; + }), + statistics_data: Ember.computed(function() { + var base_url, model_name, request, session, store, url, user_id; + if (!(user_id = this.get('user.id'))) { + return {}; + } + model_name = 'user'; + base_url = this.store.adapterFor(model_name).buildURL(model_name); + url = base_url + "/" + user_id + "/statistics1"; + session = this.get('session'); + store = this.store; + request = { + url: url, + contentType: "application/json", + dataType: "json" + }; + if (Ember.get(session, 'isAuthenticated')) { + session.authorize('authorizer:devise', function(key, authorization) { + var obj; + request.crossDomain = true; + return request.headers = ( + obj = {}, + obj["" + key] = authorization, + obj + ); + }); + } + return DS.PromiseObject.create({ + promise: Ember.RSVP.hash({ + data: Ember.$.ajax(request), + projects: store.findAll('panda/project', { + backgroundReload: false + }) + }) + }); + }) +}); diff --git a/app/components/organization-statistics1.js b/app/components/organization-statistics1.js new file mode 100644 index 0000000..d1c1160 --- /dev/null +++ b/app/components/organization-statistics1.js @@ -0,0 +1 @@ +export { default } from 'ember-panda/components/organization-statistics1'; diff --git a/app/components/user-main-statistics1.js b/app/components/user-main-statistics1.js new file mode 100644 index 0000000..2a315dc --- /dev/null +++ b/app/components/user-main-statistics1.js @@ -0,0 +1 @@ +export { default } from 'ember-panda/components/user-main-statistics1'; diff --git a/app/routes/project/index.coffee b/app/routes/project/index.coffee index e315d98..c09aa43 100644 --- a/app/routes/project/index.coffee +++ b/app/routes/project/index.coffee @@ -1,6 +1,6 @@ import Ember from 'ember' export default Ember.Route.extend - model: -> @store.findAll('panda/project') + model: -> @store.findAll('panda/project', backgroundReload: false) actions: editProjectsContext: -> @modal 'project/edit-projects-context' diff --git a/app/templates/components/organization-statistics1.emblem b/app/templates/components/organization-statistics1.emblem new file mode 100644 index 0000000..e4aa3cf --- /dev/null +++ b/app/templates/components/organization-statistics1.emblem @@ -0,0 +1,18 @@ +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 + else + /.ui.header= t 'user.statistics1.global.title' + each-in statistics as |state count| + = 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 new file mode 100644 index 0000000..dfe130c --- /dev/null +++ b/app/templates/components/user-main-statistics1.emblem @@ -0,0 +1,23 @@ +if user.email + /.ui.horizontal.divider= user.nickname + 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 + else + /.ui.header= t 'user.statistics1.global.title' + each-in statistics as |state count| + = state-badge state + ' + span.between-brackets= count + = yield + else + .ui.active.inline.centered.loader +else + .ui.active.inline.centered.loader diff --git a/app/templates/organization/index.emblem b/app/templates/organization/index.emblem index ba0ed53..786f03f 100644 --- a/app/templates/organization/index.emblem +++ b/app/templates/organization/index.emblem @@ -3,9 +3,10 @@ d-breadcrumbs as |breadcrumb| = t 'models.plural.organization' .ui.container h3.ui.top.attached.header - .ui.right.floated.icon.buttons - /= push-action type='edit' action='editOrganizationContext' - = push-action type='new' action='newOrganization' description='Add organization' + if (can 'manage' 'model' 'panda/organization') + .ui.right.floated.icon.buttons + /= push-action type='edit' action='editOrganizationContext' + = push-action type='new' action='newOrganization' description='Add organization' = t 'models.plural.organization' table.ui.unstackable.bottom.attached.table /thead @@ -19,4 +20,5 @@ d-breadcrumbs as |breadcrumb| if organization.logo img src=organization.logo_url.small td= link-to organization.name 'organization.show' organization - td.actions= push-action type='edit' action='editOrganization' model=organization + if (can 'manage' 'model' 'panda/organization') + td.actions= push-action type='edit' action='editOrganization' model=organization diff --git a/app/templates/organization/show/index.emblem b/app/templates/organization/show/index.emblem index aad7b7f..748def7 100644 --- a/app/templates/organization/show/index.emblem +++ b/app/templates/organization/show/index.emblem @@ -9,8 +9,8 @@ d-breadcrumbs as |breadcrumb| .ui.container .ui.header .ui.right.floated.icon.buttons - if is_manager - = push-action type='edit' action='editOrganization' + if (can 'manage' 'model' 'panda/organization') + = push-action type='edit' action='editOrganization' model=model h2 span.resource-descriptor= t 'models.organization' span.resource-name= model.name @@ -20,6 +20,7 @@ d-breadcrumbs as |breadcrumb| ul.ui.list li= link-to 'organization.show.project-actions' model span= t 'organization.project_actions.title' + organization-statistics1 record=model /= line-chart data=chart_data /= gantt-chart organization=model diff --git a/tests/dummy/app/i18n/translations/user.coffee b/tests/dummy/app/i18n/translations/user.coffee index 85ccda3..4ecd7a3 100644 --- a/tests/dummy/app/i18n/translations/user.coffee +++ b/tests/dummy/app/i18n/translations/user.coffee @@ -5,4 +5,10 @@ translations = user: title: 'New ${models.user}' edit_user: title: 'Edit ${models.user} %{nickname}' + statistics1: + global: + title: 'Global' + project_specific: + label: 'Per project' + export default translations diff --git a/tests/dummy/app/templates/index.emblem b/tests/dummy/app/templates/index.emblem index 696f773..8686172 100644 --- a/tests/dummy/app/templates/index.emblem +++ b/tests/dummy/app/templates/index.emblem @@ -5,6 +5,7 @@ br img.ui.centered.image src="/panda/app/assets/favicons/android-chrome-192x192.png" + = user-main-statistics1 user=globals.current_user .ui.header TODO .ui.list diff --git a/tests/integration/components/organization-statistics1-test.coffee b/tests/integration/components/organization-statistics1-test.coffee new file mode 100644 index 0000000..910cbc1 --- /dev/null +++ b/tests/integration/components/organization-statistics1-test.coffee @@ -0,0 +1,25 @@ +import { test, moduleForComponent } from 'ember-qunit' +import hbs from 'htmlbars-inline-precompile' + +moduleForComponent 'organization-statistics1', 'Integration | Component | organization statistics1', { + integration: true +} + +test 'it renders', (assert) -> + assert.expect 2 + + # Set any properties with @set 'myProperty', 'value' + # Handle any actions with @on 'myAction', (val) -> + + @render hbs """{{organization-statistics1}}""" + + assert.equal @$().text().trim(), '' + + # Template block usage: + @render hbs """ + {{#organization-statistics1}} + template block text + {{/organization-statistics1}} + """ + + assert.equal @$().text().trim(), 'template block text' diff --git a/tests/integration/components/user-main-statistics1-test.coffee b/tests/integration/components/user-main-statistics1-test.coffee new file mode 100644 index 0000000..98d6d82 --- /dev/null +++ b/tests/integration/components/user-main-statistics1-test.coffee @@ -0,0 +1,25 @@ +import { test, moduleForComponent } from 'ember-qunit' +import hbs from 'htmlbars-inline-precompile' + +moduleForComponent 'user-main-statistics1', 'Integration | Component | user main statistics1', { + integration: true +} + +test 'it renders', (assert) -> + assert.expect 2 + + # Set any properties with @set 'myProperty', 'value' + # Handle any actions with @on 'myAction', (val) -> + + @render hbs """{{user-main-statistics1}}""" + + assert.equal @$().text().trim(), '' + + # Template block usage: + @render hbs """ + {{#user-main-statistics1}} + template block text + {{/user-main-statistics1}} + """ + + assert.equal @$().text().trim(), 'template block text'