Safeguarding attached actions

This commit is contained in:
2017-12-25 13:36:09 +01:00
parent 9936a38843
commit 724a3688d9
7 changed files with 115 additions and 37 deletions
@@ -10,6 +10,8 @@ export default ModalBase.extend
new_note_content: ''
new_note_content_is_blank: Ember.computed.not 'new_note_content.length'
has_uncompleted_constraints: false
attached_instance_action_connections: []
attached_conditions_not_met_warning: ''
can_edit_action: Ember.computed 'model.workflow_action_definition.organization.users.[]', ->
return true if @get('globals.current_user.admin')
@@ -42,9 +44,22 @@ export default ModalBase.extend
@set 'number_value', @get('model.number_value')
@set 'text_value', @get('model.text_value')
@set 'timestamp_value', @get('model.timestamp_value')
@get('model.pointing_project_instance_action_connections').filterBy('connection_type', 'constraint').some (pointing_connection) =>
return @set 'has_uncompleted_constraints', true unless pointing_connection.get('project_instance_action.completed')
false
@set 'attached_instance_action_connections', []
@set 'attached_conditions_not_met_warning', '' # important te reset since attached actions can be completed on re-open of parent
@get('model.pointing_project_instance_action_connections').forEach (pointing_connection) =>
if pointing_connection.get('connection_type') is 'constraint' and not @get('has_uncompleted_constraints')
@set 'has_uncompleted_constraints', true unless pointing_connection.get('project_instance_action.completed')
if pointing_connection.get('connection_type') is 'attached'
if conditional_value = pointing_connection.get('conditional_base_value')
switch @get('model.workflow_action_definition.value_type')
when 'boolean'
3
when 'select'
@get('attached_instance_action_connections').pushObject pointing_connection if conditional_value is @get('string_value')
else
# always display non conditional attached actions
@get('attached_instance_action_connections').pushObject pointing_connection
#@get('pointing_project_instance_action_connections').forEach (pointing_connection) ->
select_class_names: Ember.computed 'model.string_value', ->
@@ -62,6 +77,8 @@ export default ModalBase.extend
actions:
set_value: (attribute, value) ->
#@set attribute, value # internal setting for validation
@set 'action_value', value
@set "model.#{attribute}", value
@send 'saveRecord'
@@ -73,6 +90,7 @@ export default ModalBase.extend
set_number_value: ->
@send 'set_value', 'number_value', @get('number_value')
set_timestamp_value: ->
@send 'set_value', 'timestamp_value', @get('timestamp_value')
@@ -110,3 +128,14 @@ export default ModalBase.extend
#record.save().then ->
# record.get('events').reload()
saveRecord: ->
all_attached_actions_are_valid = true
@set 'attached_conditions_not_met_warning', ''
@get('model.pointing_project_instance_action_connections').forEach (pointing_connection) =>
if pointing_connection.get('connection_type') is 'attached'
if conditional_value = pointing_connection.get('conditional_base_value')
if conditional_value is @get('model.string_comparison_value') and not pointing_connection.get('project_instance_action.completed')
@set 'attached_conditions_not_met_warning', "#{pointing_connection.get('project_instance_action.workflow_action_definition.title')} not completed"
all_attached_actions_are_valid = false
#alert 'Attached not completed'
@_super arguments... if all_attached_actions_are_valid