Implement statistics components

This commit is contained in:
2018-07-22 19:33:58 -05:00
parent b24b8cc525
commit 833c10ea7f
15 changed files with 383 additions and 7 deletions
@@ -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))
@@ -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
})
})
});
})
});
@@ -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))
+82
View File
@@ -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
})
})
});
})
});
@@ -0,0 +1 @@
export { default } from 'ember-panda/components/organization-statistics1';
+1
View File
@@ -0,0 +1 @@
export { default } from 'ember-panda/components/user-main-statistics1';
+1 -1
View File
@@ -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'
@@ -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
@@ -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
+6 -4
View File
@@ -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
+3 -2
View File
@@ -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
@@ -5,4 +5,10 @@ translations = user:
title: 'New ${models.user}'
edit_user:
title: 'Edit ${models.user} <strong>%{nickname}</strong>'
statistics1:
global:
title: 'Global'
project_specific:
label: 'Per project'
export default translations
+1
View File
@@ -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
@@ -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'
@@ -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'