diff --git a/.ember-cli b/.ember-cli index ee64cfe..59bb55f 100644 --- a/.ember-cli +++ b/.ember-cli @@ -5,5 +5,5 @@ Setting `disableAnalytics` to true will prevent any data from being sent. */ - "disableAnalytics": false + "disableAnalytics": true } diff --git a/addon/controllers/project/show/operate.coffee b/addon/controllers/project/show/operate.coffee new file mode 100644 index 0000000..2da4e79 --- /dev/null +++ b/addon/controllers/project/show/operate.coffee @@ -0,0 +1,12 @@ +import Ember from 'ember' +export default Ember.Controller.extend + operation_running_time: Ember.computed 'globals.operation_running', -> + return '' unless start_time = @get('globals.operation_running') + duration = moment.duration(moment().diff(start_time)) + if duration.days() + "#{duration.days()} days and #{duration.hours()} hours" + else + hours = ('0' + duration.hours()).slice(-2) + minutes = ('0' + duration.minutes()).slice(-2) + seconds = ('0' + duration.seconds()).slice(-2) + "#{hours}:#{minutes}:#{seconds}" diff --git a/addon/controllers/project/show/operate.js b/addon/controllers/project/show/operate.js new file mode 100644 index 0000000..26a5971 --- /dev/null +++ b/addon/controllers/project/show/operate.js @@ -0,0 +1,20 @@ +// Generated by CoffeeScript 1.12.5 +import Ember from 'ember'; + +export default Ember.Controller.extend({ + operation_running_time: Ember.computed('globals.operation_running', function() { + var duration, hours, minutes, seconds, start_time; + if (!(start_time = this.get('globals.operation_running'))) { + return ''; + } + duration = moment.duration(moment().diff(start_time)); + if (duration.days()) { + return (duration.days()) + " days and " + (duration.hours()) + " hours"; + } else { + hours = ('0' + duration.hours()).slice(-2); + minutes = ('0' + duration.minutes()).slice(-2); + seconds = ('0' + duration.seconds()).slice(-2); + return hours + ":" + minutes + ":" + seconds; + } + }) +}); diff --git a/addon/models/panda/setting.coffee b/addon/models/panda/setting.coffee new file mode 100644 index 0000000..f71443e --- /dev/null +++ b/addon/models/panda/setting.coffee @@ -0,0 +1,4 @@ +import DS from 'ember-data' + +export default DS.Model.extend + value: DS.attr() diff --git a/addon/models/panda/setting.js b/addon/models/panda/setting.js new file mode 100644 index 0000000..dcda52e --- /dev/null +++ b/addon/models/panda/setting.js @@ -0,0 +1,6 @@ +// Generated by CoffeeScript 1.12.5 +import DS from 'ember-data'; + +export default DS.Model.extend({ + value: DS.attr() +}); diff --git a/addon/routes/project/show/operate.coffee b/addon/routes/project/show/operate.coffee new file mode 100644 index 0000000..9cd3847 --- /dev/null +++ b/addon/routes/project/show/operate.coffee @@ -0,0 +1,44 @@ +import Ember from 'ember' +import config from 'ember-get-config' +#import Route from '@ember/route' +#import { inject as service } from '@ember/service' +export default Ember.Route.extend + poll: Ember.inject.service() + session: Ember.inject.service() + + model: -> @modelFor('project.show') + + afterModel: (model, transition) -> + model.reload() unless @controllerFor('application').get('currentRouteName') in ['loading', 'project.show.operate'] + + actions: + didTransition: -> + model_name = 'panda/setting' + base_url = @store.adapterFor(model_name).buildURL(model_name) + endpoint = "#{base_url}/operation_running/get_value" + + request = + url: endpoint + success: (operation_running) => + if operation_running + @set 'router.globals.operation_running', moment(operation_running) + else + @set 'router.globals.operation_running', '' + session = @get('session') + if Ember.get(session, 'isAuthenticated') + session.authorize 'authorizer:devise', (key, authorization) -> + request.crossDomain = true + request.headers = {"#{key}": authorization} + + pollFunction = => + Ember.$.ajax request + pollFunction() + pollId = @get('poll').addPoll + interval: 30 * 1000 + callback: pollFunction + label: 'project-running' + #@get('poll').startPoll(pollId) + #@get('poll').startPollByLabel('project-running') + + willTransition: -> + @get('poll').stopPollByLabel('project-running') diff --git a/addon/routes/project/show/operate.js b/addon/routes/project/show/operate.js new file mode 100644 index 0000000..795f15b --- /dev/null +++ b/addon/routes/project/show/operate.js @@ -0,0 +1,64 @@ +// Generated by CoffeeScript 1.12.5 +import Ember from 'ember'; + +import config from 'ember-get-config'; + +export default Ember.Route.extend({ + poll: Ember.inject.service(), + session: Ember.inject.service(), + model: function() { + return this.modelFor('project.show'); + }, + afterModel: function(model, transition) { + var ref; + if ((ref = this.controllerFor('application').get('currentRouteName')) !== 'loading' && ref !== 'project.show.operate') { + return model.reload(); + } + }, + actions: { + didTransition: function() { + var base_url, endpoint, model_name, pollFunction, pollId, request, session; + model_name = 'panda/setting'; + base_url = this.store.adapterFor(model_name).buildURL(model_name); + endpoint = base_url + "/operation_running/get_value"; + request = { + url: endpoint, + success: (function(_this) { + return function(operation_running) { + if (operation_running) { + return _this.set('router.globals.operation_running', moment(operation_running)); + } else { + return _this.set('router.globals.operation_running', ''); + } + }; + })(this) + }; + session = this.get('session'); + 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 + ); + }); + } + pollFunction = (function(_this) { + return function() { + return Ember.$.ajax(request); + }; + })(this); + pollFunction(); + return pollId = this.get('poll').addPoll({ + interval: 30 * 1000, + callback: pollFunction, + label: 'project-running' + }); + }, + willTransition: function() { + return this.get('poll').stopPollByLabel('project-running'); + } + } +}); diff --git a/addon/utils/panda-route-setup.coffee b/addon/utils/panda-route-setup.coffee index 9865764..d3ffdec 100644 --- a/addon/utils/panda-route-setup.coffee +++ b/addon/utils/panda-route-setup.coffee @@ -9,6 +9,7 @@ pandaRouteSetup = (context) -> # @route 'show' @route 'dunlop-generator' @route 'analysis' + @route 'operate' @route 'project-instance', -> @route 'show', path: ':project_instance_id', -> @route 'groups' @@ -19,6 +20,7 @@ pandaRouteSetup = (context) -> @route 'show', path: ':project_instance_group_id' @route 'project-instance-action', -> @route 'show', path: ':project_instance_action_id' + #@route 'project/views', path: 'views' context.route 'login' #@route 'organization', path: 'organizations/:organization_id' diff --git a/addon/utils/panda-route-setup.js b/addon/utils/panda-route-setup.js index 2d6e6d6..5de2485 100644 --- a/addon/utils/panda-route-setup.js +++ b/addon/utils/panda-route-setup.js @@ -14,6 +14,7 @@ pandaRouteSetup = function(context) { this.route('add-progress'); this.route('dunlop-generator'); this.route('analysis'); + this.route('operate'); this.route('project-instance', function() { return this.route('show', { path: ':project_instance_id' diff --git a/app/controllers/project/show/operate.js b/app/controllers/project/show/operate.js new file mode 100644 index 0000000..c95c910 --- /dev/null +++ b/app/controllers/project/show/operate.js @@ -0,0 +1 @@ +export { default } from 'ember-panda/controllers/project/show/operate'; diff --git a/app/routes/project/show/operate.js b/app/routes/project/show/operate.js new file mode 100644 index 0000000..127108b --- /dev/null +++ b/app/routes/project/show/operate.js @@ -0,0 +1 @@ +export { default } from 'ember-panda/routes/project/show/operate'; diff --git a/app/templates/project/show/index.emblem b/app/templates/project/show/index.emblem index 5b92eb5..b5a8bbc 100644 --- a/app/templates/project/show/index.emblem +++ b/app/templates/project/show/index.emblem @@ -23,6 +23,15 @@ d-breadcrumbs as |breadcrumb| h2.ui.header i.bar.chart.icon .content= link-to 'project.show.analysis' model: span= t 'project.analysis.title' + if (can 'operate' 'model' 'panda/project') + h2.ui.header + /i.icons + i.database.icon + i.cogs.icon + /i.paint.brush.icon + i.wrench.icon + /i.schlix.icon + .content= link-to 'project.show.operate' model: span= t 'project.operate.title' /ul.ui.list li= link-to 'project.show.dunlop' model span= t 'project.dunlop.title' diff --git a/app/templates/project/show/operate.emblem b/app/templates/project/show/operate.emblem new file mode 100644 index 0000000..c8e58bc --- /dev/null +++ b/app/templates/project/show/operate.emblem @@ -0,0 +1,22 @@ +d-breadcrumbs as |breadcrumb| + breadcrumb.item + = link-to 'project.index': span= t 'models.plural.project' + breadcrumb.item + span= t 'models.project' + span : + = link-to 'project.show' model: span= model.name + breadcrumb.item active=true + span= t 'project.operate.title' + +if globals.operation_running + .ui.segment + p   + .ui.active.inverted.dimmer: .ui.medium.text.loader + = t 'project.operate.operation_running_text' + ' + span.between-brackets= operation_running_time + p   + p   +else + .ui.horizontal.divider= t 'project.operate.set_value_on_non_final_with_closed_group.title' + .ui.segment diff --git a/package.json b/package.json index 7b0caa2..ffa0efe 100644 --- a/package.json +++ b/package.json @@ -59,6 +59,7 @@ "ember-load-initializers": "^1.0.0", "ember-math-helpers": "^2.2.3", "ember-one-way-controls": "^2.0.1", + "ember-poll": "^1.4.0", "ember-resolver": "^4.0.0", "ember-route-action-helper": "^2.0.6", "ember-semantic-ui-calendar": "^1.0.1", diff --git a/tests/dummy/app/i18n/translations/project.coffee b/tests/dummy/app/i18n/translations/project.coffee index e51abcd..d29454c 100644 --- a/tests/dummy/app/i18n/translations/project.coffee +++ b/tests/dummy/app/i18n/translations/project.coffee @@ -33,4 +33,9 @@ translations = project: show: dunlop_project_info: title: "${models.project} %{name} info" + operate: + title: '${models.project} operations' + operation_running_text: 'There already is an operation running' + set_value_on_non_final_with_closed_group: + title: 'Set value on actions where group is closed' export default translations diff --git a/tests/dummy/app/initializers/globals.coffee b/tests/dummy/app/initializers/globals.coffee index 5f75837..d56c693 100644 --- a/tests/dummy/app/initializers/globals.coffee +++ b/tests/dummy/app/initializers/globals.coffee @@ -28,6 +28,8 @@ default_globals = workflow_group: batch_element_threshold_unit_options: ['businessday', 'day', 'week'] + operation_running: '' # should be set to false through api call + project_instance: states: ['uncategorized', 'unplanned', 'planned', 'active', 'overdue', 'any_rejected', 'all_completed']