Implement statistics components
This commit is contained in:
@@ -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))
|
||||
@@ -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
|
||||
})
|
||||
})
|
||||
});
|
||||
})
|
||||
});
|
||||
Reference in New Issue
Block a user