90 lines
2.7 KiB
JavaScript
90 lines
2.7 KiB
JavaScript
// Generated by CoffeeScript 2.7.0
|
|
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'),
|
|
classNames: ['project-aggregate-statistics', 'project-aggregate-user-statistics'],
|
|
statistics: Ember.computed('statistics_data.isFulfilled', 'project_specific', function() {
|
|
var count, d, project, project_id, 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']
|
|
states = this.get('globals.project_instance_action.states');
|
|
project_specific = this.get('project_specific');
|
|
if (!project_specific) {
|
|
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);
|
|
target[project_id] = {
|
|
project: project,
|
|
states: []
|
|
};
|
|
states.forEach(function(state) {
|
|
return target[project_id].states.push({
|
|
state: state,
|
|
count: stats[state] || 0
|
|
});
|
|
});
|
|
} else {
|
|
for (state in stats) {
|
|
count = stats[state];
|
|
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
|
|
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"
|
|
};
|
|
//success: (response) ->
|
|
// resolve(response)
|
|
if (Ember.get(session, 'isAuthenticated')) {
|
|
session.authorize('authorizer:devise', function(key, authorization) {
|
|
request.crossDomain = true;
|
|
return request.headers = {
|
|
[`${key}`]: authorization
|
|
};
|
|
});
|
|
}
|
|
return DS.PromiseObject.create({
|
|
promise: Ember.RSVP.hash({
|
|
data: Ember.$.ajax(request),
|
|
projects: store.findAll('panda/project', {
|
|
backgroundReload: false
|
|
})
|
|
})
|
|
});
|
|
})
|
|
});
|