Files
ember-panda/addon/controllers/action-list.js
T
2023-11-28 14:30:02 -05:00

125 lines
4.9 KiB
JavaScript

// Generated by CoffeeScript 2.7.0
import Ember from 'ember';
//import config from 'ember-get-config'
export default Ember.Controller.extend({
session: Ember.inject.service('session'),
//filters: {filter_calls: 0} # will be overwritten in route
//filters: Ember.computed.alias 'model.project_instance_actions.filters'
scope_project: null,
scope_scenario: null,
scope_organization: null,
projects: (function() {
return this.store.findAll('panda/project');
}).property(),
sorted_projects: Ember.computed('projects.@each.name', function() {
return this.get('projects').sortBy('name');
}),
show_completed_at: Ember.computed('filters.state_in.[]', 'filters.completed_at_gteq', 'filters.completed_at_lteq', 'filters.s', function() {
if (this.get('filters.completed_at_lteq') || this.get('filters.completed_at_gteq')) {
return true;
}
if (/^completed_at/.test(this.get('filters.s'))) {
return true;
}
return JSON.stringify(this.get('filters.state_in')) === '["completed"]';
}),
show_inquiry_at: Ember.computed('filters.state_in.[]', 'filters.inquiry_at_gteq', 'filters.inquiry_at_lteq', 'filters.s', function() {
if (this.get('filters.inquiry_at_lteq') || this.get('filters.inquiry_at_gteq')) {
return true;
}
if (/^inquiry_at/.test(this.get('filters.s'))) {
return true;
}
return JSON.stringify(this.get('filters.state_in')) === '["inquiry"]';
}),
filter_query: Ember.computed('filters.filter_calls', function() {
var ref;
return ((ref = this.get('filters')) != null ? ref.toProperties() : void 0) || {};
}),
export_human_url: Ember.computed('filter_query', function() {
var base_url, filter_addition, model_name;
model_name = 'panda/project-instance-action';
base_url = this.store.adapterFor(model_name).buildURL(model_name);
filter_addition = Ember.$.param({
q: this.get('filter_query'),
include_pointing: true
});
return `${base_url}/export_human.csv?${filter_addition}`;
}),
export_technical_url: Ember.computed('filter_query', function() {
var base_url, filter_addition, model_name;
model_name = 'panda/project-instance-action';
base_url = this.store.adapterFor(model_name).buildURL(model_name);
filter_addition = Ember.$.param({
q: this.get('filter_query'),
include_pointing: true
});
return `${base_url}/export_technical.csv?${filter_addition}`;
}),
actions: {
apply_filters: function() {
var current_scope_project_id, project, project_ids, ref;
this.incrementProperty('filters.filter_calls');
current_scope_project_id = this.get('scope_project.id');
if (project_ids = this.get('filters.project_id_in')) {
if (project_ids.length === 1) {
if (current_scope_project_id !== project_ids[0]) {
project = this.store.peekRecord('panda/project', project_ids[0]);
if (this.get('filters.workflow_action_definition_title_cont')) { // this field disappears since actual action matching is assumed
this.set('filters.workflow_action_definition_title_cont', '');
}
project.reload().then(() => {
return this.set('scope_project', project);
});
}
} else if (this.get('scope_project')) {
this.set('scope_project', null);
this.set('filters.project_instance_project_scenario_id_in', []);
this.set('filters.project_instance_group_workflow_group_id_in', []);
this.set('filters.workflow_action_definition_identifier_in', []);
}
} else if (this.get('scope_project')) {
this.set('scope_project', null);
this.set('filters.project_instance_project_scenario_id_in', []);
this.set('filters.project_instance_group_workflow_group_id_in', []);
this.set('filters.workflow_action_definition_identifier_in', []);
}
if ((ref = this.get('model.project_instance_actions')) != null) {
ref.reload();
}
return false;
},
edit_project_instance_action: function(project_instance_action) {
return this.modal('project/edit-instance-action', {
model: project_instance_action
});
},
toggle_filter: function(key, value, checked) {
var new_value;
new_value = [];
if (checked) {
new_value = new_value.concat(this.get(`filters.${key}`)).concat(value);
} else {
this.get(`filters.${key}`).forEach(function(present_in_filter) {
if (present_in_filter !== value) {
return new_value.push(present_in_filter);
}
});
}
this.set(`filters.${key}`, new_value);
return this.apply_filters();
},
clear_filter: function(...keys) {
keys.forEach((key) => {
if (Ember.isArray(this.get(`filters.${key}`))) {
return this.set(`filters.${key}`, []);
} else {
return this.set(`filters.${key}`, null);
}
});
return this.apply_filters();
}
}
});