Fetch project after update attributes, custom fields or values

stable
Daniel García 2018-11-22 15:02:17 +01:00 committed by Alex Hermida
parent 22e5a8e247
commit 2855706c78
5 changed files with 58 additions and 23 deletions

View File

@ -200,7 +200,7 @@ module.directive("tgProjectProfile", ["$tgRepo", "$tgConfirm", "$tgLoading", "$t
## Project Default Values Directive ## Project Default Values Directive
############################################################################# #############################################################################
ProjectDefaultValuesDirective = ($repo, $confirm, $loading) -> ProjectDefaultValuesDirective = ($rootScope, $repo, $confirm, $loading) ->
link = ($scope, $el, $attrs) -> link = ($scope, $el, $attrs) ->
form = $el.find("form").checksley({"onlyOneErrorElement": true}) form = $el.find("form").checksley({"onlyOneErrorElement": true})
submit = debounce 2000, (event) => submit = debounce 2000, (event) =>
@ -216,6 +216,7 @@ ProjectDefaultValuesDirective = ($repo, $confirm, $loading) ->
promise.then -> promise.then ->
currentLoading.finish() currentLoading.finish()
$confirm.notify("success") $confirm.notify("success")
$rootScope.$broadcast("admin:project-default-values:updated")
promise.then null, (data) -> promise.then null, (data) ->
currentLoading.finish() currentLoading.finish()
@ -232,14 +233,14 @@ ProjectDefaultValuesDirective = ($repo, $confirm, $loading) ->
return {link:link} return {link:link}
module.directive("tgProjectDefaultValues", ["$tgRepo", "$tgConfirm", "$tgLoading", module.directive("tgProjectDefaultValues", ["$rootScope", "$tgRepo", "$tgConfirm", "$tgLoading",
ProjectDefaultValuesDirective]) ProjectDefaultValuesDirective])
############################################################################# #############################################################################
## Project Modules Directive ## Project Modules Directive
############################################################################# #############################################################################
ProjectModulesDirective = ($repo, $confirm, $loading, projectService) -> ProjectModulesDirective = ($rootScope, $repo, $confirm, $loading) ->
link = ($scope, $el, $attrs) -> link = ($scope, $el, $attrs) ->
submit = => submit = =>
form = $el.find("form").checksley() form = $el.find("form").checksley()
@ -250,10 +251,9 @@ ProjectModulesDirective = ($repo, $confirm, $loading, projectService) ->
promise = $repo.save($scope.project) promise = $repo.save($scope.project)
promise.then -> promise.then ->
$scope.$emit("project:loaded", $scope.project) $scope.$emit("project:loaded", $scope.project)
$rootScope.$broadcast("admin:project-modules:updated")
$confirm.notify("success") $confirm.notify("success")
projectService.fetchProject()
promise.then null, (data) -> promise.then null, (data) ->
form.setErrors(data) form.setErrors(data)
if data._error_message if data._error_message
@ -298,7 +298,7 @@ ProjectModulesDirective = ($repo, $confirm, $loading, projectService) ->
return {link:link} return {link:link}
module.directive("tgProjectModules", ["$tgRepo", "$tgConfirm", "$tgLoading", "tgProjectService", module.directive("tgProjectModules", ["$rootScope", "$tgRepo", "$tgConfirm", "$tgLoading",
ProjectModulesDirective]) ProjectModulesDirective])

View File

@ -120,7 +120,8 @@ class ProjectValuesController extends taiga.Controller
_.each values, (value, index) -> _.each values, (value, index) ->
value.order = index value.order = index
@repo.saveAll(values) @repo.saveAll(values).then () =>
@rootscope.$broadcast("admin:project-values:updated")
module.controller("ProjectValuesController", ProjectValuesController) module.controller("ProjectValuesController", ProjectValuesController)
@ -151,6 +152,7 @@ class ProjectDueDatesValuesController extends ProjectValuesController
if !@rs[@scope.resource].createDefaultValues? if !@rs[@scope.resource].createDefaultValues?
return return
return @rs[@scope.resource].createDefaultValues(@scope.projectId, @scope.type).then (response) => return @rs[@scope.resource].createDefaultValues(@scope.projectId, @scope.type).then (response) =>
@rootscope.$broadcast("admin:project-values:updated")
values = response.data values = response.data
if values.length if values.length
@scope.maxValueOrder = _.maxBy(values, "order").order @scope.maxValueOrder = _.maxBy(values, "order").order
@ -244,10 +246,11 @@ ProjectValuesDirective = ($log, $repo, $confirm, $location, animationFrame, $tra
value = formEl.scope().value value = formEl.scope().value
promise = $repo.save(value) promise = $repo.save(value)
promise.then => promise.then ->
row = target.parents(".row.table-main") row = target.parents(".row.table-main")
row.addClass("hidden") row.addClass("hidden")
row.siblings(".visualization").removeClass('hidden') row.siblings(".visualization").removeClass('hidden')
$rootscope.$broadcast("admin:project-values:updated")
projectService.fetchProject() projectService.fetchProject()
@ -269,6 +272,7 @@ ProjectValuesDirective = ($log, $repo, $confirm, $location, animationFrame, $tra
$scope.values.push(data) $scope.values.push(data)
$scope.maxValueOrder = data.order $scope.maxValueOrder = data.order
initializeNewValue() initializeNewValue()
$rootscope.$broadcast("admin:project-values:updated")
promise.then null, (data) -> promise.then null, (data) ->
form.setErrors(data) form.setErrors(data)
@ -349,6 +353,7 @@ ProjectValuesDirective = ($log, $repo, $confirm, $location, animationFrame, $tra
$confirm.askChoice(title, subtitle, choices, text).then (response) -> $confirm.askChoice(title, subtitle, choices, text).then (response) ->
onSucces = -> onSucces = ->
$ctrl.loadValues().finally -> $ctrl.loadValues().finally ->
$rootscope.$broadcast("admin:project-values:updated")
response.finish() response.finish()
onError = -> onError = ->
$confirm.notify("error") $confirm.notify("error")
@ -374,7 +379,8 @@ ProjectDueDatesValues = ($log, $repo, $confirm, $location, animationFrame, $tran
parentDirective = ProjectValuesDirective($log, $repo, $confirm, $location, animationFrame, parentDirective = ProjectValuesDirective($log, $repo, $confirm, $location, animationFrame,
$translate, $rootscope, projectService) $translate, $rootscope, projectService)
linkDueDateStatusValue = ($scope, $el, $attrs) -> linkDueDateStatusValue = ($scope, $el, $attrs, $ctrl) ->
$ctrl = $el.controller()
valueType = $attrs.type valueType = $attrs.type
initializeNewValue = -> initializeNewValue = ->
@ -414,7 +420,7 @@ ProjectDueDatesValues = ($log, $repo, $confirm, $location, animationFrame, $tran
data.days_to_due_abs = $scope.newValue.days_to_due_abs data.days_to_due_abs = $scope.newValue.days_to_due_abs
$scope.values.push(data) $scope.values.push(data)
$rootscope.$broadcast("admin:project-values:updated")
initializeNewValue() initializeNewValue()
promise.then null, (data) -> promise.then null, (data) ->
@ -451,6 +457,7 @@ ProjectDueDatesValues = ($log, $repo, $confirm, $location, animationFrame, $tran
$confirm.ask(title, subtitle).then (response) -> $confirm.ask(title, subtitle).then (response) ->
onSucces = -> onSucces = ->
$ctrl.loadValues().finally -> $ctrl.loadValues().finally ->
$rootscope.$broadcast("admin:project-values:updated")
response.finish() response.finish()
onError = -> onError = ->
$confirm.notify("error") $confirm.notify("error")
@ -628,6 +635,9 @@ class ProjectCustomAttributesController extends mixOf(taiga.Controller, taiga.Pa
attr.extra = [''] attr.extra = ['']
return attr return attr
_onCustomAttributesModified: =>
@rootscope.$broadcast("admin:project-custom-attributes:updated")
loadCustomAttributes: => loadCustomAttributes: =>
return @rs.customAttributes[@scope.type].list(@scope.projectId).then (customAttributes) => return @rs.customAttributes[@scope.type].list(@scope.projectId).then (customAttributes) =>
@scope.customAttributes = customAttributes @scope.customAttributes = customAttributes
@ -636,13 +646,16 @@ class ProjectCustomAttributesController extends mixOf(taiga.Controller, taiga.Pa
return customAttributes return customAttributes
createCustomAttribute: (attrValues) => createCustomAttribute: (attrValues) =>
return @repo.create("custom-attributes/#{@scope.type}", attrValues) return @repo.create("custom-attributes/#{@scope.type}", attrValues).then =>
@._onCustomAttributesModified()
saveCustomAttribute: (attrModel) => saveCustomAttribute: (attrModel) =>
return @repo.save(attrModel) return @repo.save(attrModel).then =>
@._onCustomAttributesModified()
deleteCustomAttribute: (attrModel) => deleteCustomAttribute: (attrModel) =>
return @repo.remove(attrModel) return @repo.remove(attrModel).then =>
@._onCustomAttributesModified()
moveCustomAttributes: (attrModel, newIndex) => moveCustomAttributes: (attrModel, newIndex) =>
customAttributes = @scope.customAttributes customAttributes = @scope.customAttributes
@ -653,7 +666,8 @@ class ProjectCustomAttributesController extends mixOf(taiga.Controller, taiga.Pa
_.each customAttributes, (val, idx) -> _.each customAttributes, (val, idx) ->
val.order = idx val.order = idx
@repo.saveAll(customAttributes) @repo.saveAll(customAttributes).then =>
@._onCustomAttributesModified()
module.controller("ProjectCustomAttributesController", ProjectCustomAttributesController) module.controller("ProjectCustomAttributesController", ProjectCustomAttributesController)
@ -1099,7 +1113,7 @@ ProjectTagsDirective = ($log, $repo, $confirm, $location, animationFrame, $trans
if focus if focus
$el.find(".new-value input:visible").first().focus() $el.find(".new-value input:visible").first().focus()
saveValue = (target) => saveValue = (target) ->
formEl = target.parents("form") formEl = target.parents("form")
form = formEl.checksley() form = formEl.checksley()
return if not form.validate() return if not form.validate()
@ -1110,18 +1124,19 @@ ProjectTagsDirective = ($log, $repo, $confirm, $location, animationFrame, $trans
$scope.loadingEdit = true $scope.loadingEdit = true
promise = $ctrl.editTag(originalTag.name, tag.name, tag.color) promise = $ctrl.editTag(originalTag.name, tag.name, tag.color)
promise.then => promise.then ->
$ctrl.loadTags().then => $ctrl.loadTags().then ->
row = target.parents(".row.table-main") row = target.parents(".row.table-main")
row.addClass("hidden") row.addClass("hidden")
$scope.loadingEdit = false $scope.loadingEdit = false
$rootscope.$broadcast('tags:updated')
row.siblings(".visualization").removeClass('hidden') row.siblings(".visualization").removeClass('hidden')
promise.then null, (response) -> promise.then null, (response) ->
$scope.loadingEdit = false $scope.loadingEdit = false
form.setErrors(response.data) form.setErrors(response.data)
saveNewValue = (target) => saveNewValue = (target) ->
formEl = target.parents("form") formEl = target.parents("form")
formEl = target formEl = target
form = formEl.checksley() form = formEl.checksley()
@ -1129,10 +1144,11 @@ ProjectTagsDirective = ($log, $repo, $confirm, $location, animationFrame, $trans
$scope.loadingCreate = true $scope.loadingCreate = true
promise = $ctrl.createTag($scope.newValue.tag, $scope.newValue.color) promise = $ctrl.createTag($scope.newValue.tag, $scope.newValue.color)
promise.then (data) => promise.then (data) ->
$ctrl.loadTags().then => $ctrl.loadTags().then ->
$scope.loadingCreate = false $scope.loadingCreate = false
target.addClass("hidden") target.addClass("hidden")
$rootscope.$broadcast('tags:updated')
initializeNewValue() initializeNewValue()
promise.then null, (response) -> promise.then null, (response) ->
@ -1242,6 +1258,7 @@ ProjectTagsDirective = ($log, $repo, $confirm, $location, animationFrame, $trans
$confirm.askOnDelete(title, tag.name).then (response) -> $confirm.askOnDelete(title, tag.name).then (response) ->
onSucces = -> onSucces = ->
$ctrl.loadTags().finally -> $ctrl.loadTags().finally ->
$rootscope.$broadcast('tags:updated')
response.finish() response.finish()
onError = -> onError = ->
$confirm.notify("error") $confirm.notify("error")

View File

@ -106,8 +106,7 @@ class RolesController extends mixOf(taiga.Controller, taiga.PageMixin, taiga.Fil
return @.loadRoles() return @.loadRoles()
forceLoadProject: () -> forceLoadProject: () ->
@projectService.fetchProject () => @rootscope.$broadcast("admin:project-roles:updated")
@.loadProject()
setRole: (role) -> setRole: (role) ->
@scope.role = role @scope.role = role

View File

@ -63,6 +63,7 @@ class TagLineController
onAddTagSuccess = (item) => onAddTagSuccess = (item) =>
@rootScope.$broadcast("object:updated") #its a kind of magic. @rootScope.$broadcast("object:updated") #its a kind of magic.
@rootScope.$broadcast("tags:updated")
@.addTag = false @.addTag = false
@.loadingAddTag = false @.loadingAddTag = false

View File

@ -21,13 +21,14 @@ taiga = @.taiga
class ProjectService class ProjectService
@.$inject = [ @.$inject = [
"$rootScope",
"tgProjectsService", "tgProjectsService",
"tgXhrErrorService", "tgXhrErrorService",
"tgUserActivityService", "tgUserActivityService",
"$interval" "$interval"
] ]
constructor: (@projectsService, @xhrError, @userActivityService, @interval) -> constructor: (@rootScope, @projectsService, @xhrError, @userActivityService, @interval) ->
@._project = null @._project = null
@._section = null @._section = null
@._sectionsBreadcrumb = Immutable.List() @._sectionsBreadcrumb = Immutable.List()
@ -39,6 +40,23 @@ class ProjectService
taiga.defineImmutableProperty @, "activeMembers", () => return @._activeMembers taiga.defineImmutableProperty @, "activeMembers", () => return @._activeMembers
@.autoRefresh() if !window.localStorage.e2e @.autoRefresh() if !window.localStorage.e2e
@.watchSignals()
watchSignals: () ->
fetchRequiredSignals = [
"admin:project-modules:updated"
"admin:project-roles:updated"
"admin:project-default-values:updated"
"admin:project-values:updated"
"admin:project-values:move"
"admin:project-custom-attributes:updated"
"tags:updated"
]
for signal in fetchRequiredSignals
@rootScope.$on(signal, @.manageProjectSignal)
manageProjectSignal: (ctx) =>
@.fetchProject()
cleanProject: () -> cleanProject: () ->
@._project = null @._project = null