detail model transformation to prevent collisions

stable
Juanfran 2016-05-12 14:43:17 +02:00 committed by David Barragán Merino
parent 3466bf8333
commit 163fb4ab52
14 changed files with 357 additions and 271 deletions

View File

@ -263,6 +263,51 @@ Qqueue = ($q) ->
module.factory("$tgQqueue", ["$q", Qqueue])
#############################################################################
## Queue model transformation
#############################################################################
class QueueModelTransformation extends taiga.Service
@.$inject = [
"$tgQqueue",
"$tgRepo",
"$q",
"$tgModel"
]
constructor: (@qqueue, @repo, @q, @model) ->
setObject: (@scope, @prop) ->
clone: () ->
attrs = _.cloneDeep(@.scope[@.prop]._attrs)
model = @model.make_model(@.scope[@.prop]._name, attrs)
return model
getObj: () ->
return @.scope[@.prop]
save: (transformation) ->
defered = @q.defer()
@qqueue.add () =>
clone = @.clone()
transformation(clone)
success = () =>
@.scope[@.prop] = clone
defered.resolve.apply(null, arguments)
@repo.save(clone).then(success, defered.reject)
return defered.promise
module.service("$tgQueueModelTransformation", QueueModelTransformation)
#############################################################################
## Templates
#############################################################################

View File

@ -169,7 +169,7 @@ module.directive("tgCreatedByDisplay", ["$tgTemplate", "$compile", "$translate",
## Watchers directive
#############################################################################
WatchersDirective = ($rootscope, $confirm, $repo, $qqueue, $template, $compile, $translate) ->
WatchersDirective = ($rootscope, $confirm, $repo, $modelTransform, $template, $compile, $translate) ->
# You have to include a div with the tg-lb-watchers directive in the page
# where use this directive
template = $template.get("common/components/watchers.html", true)
@ -178,32 +178,33 @@ WatchersDirective = ($rootscope, $confirm, $repo, $qqueue, $template, $compile,
isEditable = ->
return $scope.project?.my_permissions?.indexOf($attrs.requiredPerm) != -1
save = $qqueue.bindAdd (watchers) =>
item = $model.$modelValue.clone()
item.watchers = watchers
$model.$setViewValue(item)
save = (watchers) ->
transform = $modelTransform.save (item) ->
item.watchers = watchers
promise = $repo.save($model.$modelValue)
promise.then ->
return item
transform.then ->
watchers = _.map(watchers, (watcherId) -> $scope.usersById[watcherId])
renderWatchers(watchers)
$rootscope.$broadcast("object:updated")
promise.then null, ->
$model.$modelValue.revert()
transform.then null, ->
$confirm.notify("error")
deleteWatcher = $qqueue.bindAdd (watcherIds) =>
item = $model.$modelValue.clone()
item.watchers = watcherIds
$model.$setViewValue(item)
deleteWatcher = (watcherIds) ->
transform = $modelTransform.save (item) ->
item.watchers = watcherIds
promise = $repo.save($model.$modelValue)
promise.then ->
return item
transform.then () ->
item = $modelTransform.getObj()
watchers = _.map(item.watchers, (watcherId) -> $scope.usersById[watcherId])
renderWatchers(watchers)
$rootscope.$broadcast("object:updated")
promise.then null, ->
transform.then null, ->
item.revert()
$confirm.notify("error")
@ -250,7 +251,7 @@ WatchersDirective = ($rootscope, $confirm, $repo, $qqueue, $template, $compile,
return {link:link, require:"ngModel"}
module.directive("tgWatchers", ["$rootScope", "$tgConfirm", "$tgRepo", "$tgQqueue", "$tgTemplate", "$compile",
module.directive("tgWatchers", ["$rootScope", "$tgConfirm", "$tgRepo", "$tgQueueModelTransformation", "$tgTemplate", "$compile",
"$translate", WatchersDirective])
@ -258,7 +259,7 @@ module.directive("tgWatchers", ["$rootScope", "$tgConfirm", "$tgRepo", "$tgQqueu
## Assigned to directive
#############################################################################
AssignedToDirective = ($rootscope, $confirm, $repo, $loading, $qqueue, $template, $translate, $compile, $currentUserService) ->
AssignedToDirective = ($rootscope, $confirm, $repo, $loading, $modelTransform, $template, $translate, $compile, $currentUserService) ->
# You have to include a div with the tg-lb-assignedto directive in the page
# where use this directive
template = $template.get("common/components/assigned-to.html", true)
@ -267,24 +268,29 @@ AssignedToDirective = ($rootscope, $confirm, $repo, $loading, $qqueue, $template
isEditable = ->
return $scope.project?.my_permissions?.indexOf($attrs.requiredPerm) != -1
save = $qqueue.bindAdd (userId) =>
$model.$modelValue.assigned_to = userId
save = (userId) ->
item = $model.$modelValue.clone()
item.assigned_to = userId
currentLoading = $loading()
.target($el)
.start()
promise = $repo.save($model.$modelValue)
promise.then ->
transform = $modelTransform.save (item) ->
item.assigned_to = userId
return item
transform.then ->
currentLoading.finish()
renderAssignedTo($model.$modelValue)
renderAssignedTo($modelTransform.getObj())
$rootscope.$broadcast("object:updated")
promise.then null, ->
$model.$modelValue.revert()
transform.then null, ->
$confirm.notify("error")
currentLoading.finish()
return promise
return transform
renderAssignedTo = (assignedObject) ->
if assignedObject?.assigned_to?
@ -347,7 +353,7 @@ AssignedToDirective = ($rootscope, $confirm, $repo, $loading, $qqueue, $template
require:"ngModel"
}
module.directive("tgAssignedTo", ["$rootScope", "$tgConfirm", "$tgRepo", "$tgLoading", "$tgQqueue", "$tgTemplate", "$translate", "$compile","tgCurrentUserService",
module.directive("tgAssignedTo", ["$rootScope", "$tgConfirm", "$tgRepo", "$tgLoading", "$tgQueueModelTransformation", "$tgTemplate", "$translate", "$compile","tgCurrentUserService",
AssignedToDirective])
@ -447,7 +453,7 @@ module.directive("tgDeleteButton", ["$log", "$tgRepo", "$tgConfirm", "$tgLocatio
## Editable subject directive
#############################################################################
EditableSubjectDirective = ($rootscope, $repo, $confirm, $loading, $qqueue, $template) ->
EditableSubjectDirective = ($rootscope, $repo, $confirm, $loading, $modelTransform, $template) ->
template = $template.get("common/components/editable-subject.html")
link = ($scope, $el, $attrs, $model) ->
@ -459,25 +465,29 @@ EditableSubjectDirective = ($rootscope, $repo, $confirm, $loading, $qqueue, $tem
isEditable = ->
return $scope.project.my_permissions.indexOf($attrs.requiredPerm) != -1
save = $qqueue.bindAdd (subject) =>
$model.$modelValue.subject = subject
save = (subject) ->
currentLoading = $loading()
.target($el.find('.save-container'))
.start()
promise = $repo.save($model.$modelValue)
promise.then ->
transform = $modelTransform.save (item) ->
item.subject = subject
return item
transform.then =>
$confirm.notify("success")
$rootscope.$broadcast("object:updated")
$el.find('.edit-subject').hide()
$el.find('.view-subject').show()
promise.then null, ->
transform.then null, ->
$confirm.notify("error")
promise.finally ->
transform.finally ->
currentLoading.finish()
return promise
return transform
$el.click ->
return if not isEditable()
@ -521,7 +531,7 @@ EditableSubjectDirective = ($rootscope, $repo, $confirm, $loading, $qqueue, $tem
template: template
}
module.directive("tgEditableSubject", ["$rootScope", "$tgRepo", "$tgConfirm", "$tgLoading", "$tgQqueue",
module.directive("tgEditableSubject", ["$rootScope", "$tgRepo", "$tgConfirm", "$tgLoading", "$tgQueueModelTransformation",
"$tgTemplate", EditableSubjectDirective])
@ -529,7 +539,7 @@ module.directive("tgEditableSubject", ["$rootScope", "$tgRepo", "$tgConfirm", "$
## Editable description directive
#############################################################################
EditableDescriptionDirective = ($rootscope, $repo, $confirm, $compile, $loading, $selectedText, $qqueue, $template, $translate) ->
EditableDescriptionDirective = ($rootscope, $repo, $confirm, $compile, $loading, $selectedText, $modelTransform, $template, $translate) ->
template = $template.get("common/components/editable-description.html")
noDescriptionMegEditMode = $template.get("common/components/editable-description-msg-edit-mode.html")
noDescriptionMegReadMode = $template.get("common/components/editable-description-msg-read-mode.html")
@ -545,22 +555,26 @@ EditableDescriptionDirective = ($rootscope, $repo, $confirm, $compile, $loading,
isEditable = ->
return $scope.project.my_permissions.indexOf($attrs.requiredPerm) != -1
save = $qqueue.bindAdd (description) =>
$model.$modelValue.description = description
save = (description) ->
currentLoading = $loading()
.target($el.find('.save-container'))
.start()
promise = $repo.save($model.$modelValue)
promise.then ->
transform = $modelTransform.save (item) ->
item.description = description
return item
transform.then ->
$confirm.notify("success")
$rootscope.$broadcast("object:updated")
$el.find('.edit-description').hide()
$el.find('.view-description').show()
promise.then null, ->
transform.then null, ->
$confirm.notify("error")
promise.finally ->
transform.finally ->
currentLoading.finish()
cancelEdition = () ->
@ -631,7 +645,7 @@ module.directive("tgEditableDescription", [
"$compile",
"$tgLoading",
"$selectedText",
"$tgQqueue",
"$tgQueueModelTransformation",
"$tgTemplate",
"$translate",
EditableDescriptionDirective])

View File

@ -80,7 +80,7 @@ module.directive("tgLbUsEstimation", ["$tgEstimationsService", "$rootScope", "$t
## User story estimation directive
#############################################################################
UsEstimationDirective = ($tgEstimationsService, $rootScope, $repo, $qqueue, $template, $compile) ->
UsEstimationDirective = ($tgEstimationsService, $rootScope, $repo, $template, $compile) ->
# Display the points of a US and you can edit it.
#
# Example:
@ -91,11 +91,14 @@ UsEstimationDirective = ($tgEstimationsService, $rootScope, $repo, $qqueue, $tem
# - scope.project object
link = ($scope, $el, $attrs, $model) ->
$scope.$watch $attrs.ngModel, (us) ->
$scope.$watchCollection () ->
return $model.$modelValue && $model.$modelValue.points
, () ->
us = $model.$modelValue
if us
estimationProcess = $tgEstimationsService.create($el, us, $scope.project)
estimationProcess.onSelectedPointForRole = (roleId, pointId) ->
@save(roleId, pointId).then ->
@save(roleId, pointId).then () ->
$rootScope.$broadcast("object:updated")
estimationProcess.render = () ->
@ -121,7 +124,7 @@ UsEstimationDirective = ($tgEstimationsService, $rootScope, $repo, $qqueue, $tem
require: "ngModel"
}
module.directive("tgUsEstimation", ["$tgEstimationsService", "$rootScope", "$tgRepo", "$tgQqueue",
module.directive("tgUsEstimation", ["$tgEstimationsService", "$rootScope", "$tgRepo",
"$tgTemplate", "$compile", UsEstimationDirective])
@ -129,7 +132,7 @@ module.directive("tgUsEstimation", ["$tgEstimationsService", "$rootScope", "$tgR
## Estimations service
#############################################################################
EstimationsService = ($template, $qqueue, $repo, $confirm, $q) ->
EstimationsService = ($template, $modelTransform, $repo, $confirm, $q) ->
pointsTemplate = $template.get("common/estimation/us-estimation-points.html", true)
class EstimationProcess
@ -143,17 +146,23 @@ EstimationsService = ($template, $qqueue, $repo, $confirm, $q) ->
save: (roleId, pointId) ->
deferred = $q.defer()
$qqueue.add () =>
onSuccess = =>
deferred.resolve()
onError = =>
$confirm.notify("error")
@us.revert()
@render()
deferred.reject()
transform = $modelTransform.save (us) =>
points = _.clone(@us.points, true)
points[roleId] = pointId
$repo.save(@us).then(onSuccess, onError)
us.points = points
return us
onSuccess = =>
deferred.resolve()
onError = =>
$confirm.notify("error")
deferred.reject()
transform.then(onSuccess, onError)
return deferred.promise
@ -197,10 +206,6 @@ EstimationsService = ($template, $qqueue, $repo, $confirm, $q) ->
roleId = target.data("role-id")
pointId = target.data("point-id")
@$el.find(".popover").popover().close()
points = _.clone(@us.points, true)
points[roleId] = pointId
@us.points = points
@render()
@onSelectedPointForRole(roleId, pointId)
renderPointsSelector: (roleId, target) ->
@ -247,5 +252,5 @@ EstimationsService = ($template, $qqueue, $repo, $confirm, $q) ->
create: create
}
module.factory("$tgEstimationsService", ["$tgTemplate", "$tgQqueue", "$tgRepo", "$tgConfirm",
module.factory("$tgEstimationsService", ["$tgTemplate", "$tgQueueModelTransformation", "$tgRepo", "$tgConfirm",
"$q", EstimationsService])

View File

@ -169,47 +169,51 @@ module.directive("lightbox", ["lightboxService", LightboxDirective])
# Issue/Userstory blocking message lightbox directive.
BlockLightboxDirective = ($rootscope, $tgrepo, $confirm, lightboxService, $loading, $qqueue, $translate) ->
BlockLightboxDirective = ($rootscope, $tgrepo, $confirm, lightboxService, $loading, $modelTransform, $translate) ->
link = ($scope, $el, $attrs, $model) ->
title = $translate.instant($attrs.title)
$el.find("h2.title").text(title)
unblock = $qqueue.bindAdd (item, finishCallback) =>
promise = $tgrepo.save(item)
promise.then ->
unblock = (finishCallback) =>
transform = $modelTransform.save (item) ->
item.is_blocked = false
item.blocked_note = ""
return item
transform.then ->
$confirm.notify("success")
$rootscope.$broadcast("object:updated")
$model.$setViewValue(item)
finishCallback()
promise.then null, ->
transform.then null, ->
$confirm.notify("error")
item.revert()
$model.$setViewValue(item)
promise.finally ->
transform.finally ->
finishCallback()
return promise
block = $qqueue.bindAdd (item) =>
$model.$setViewValue(item)
return transform
block = () ->
currentLoading = $loading()
.target($el.find(".button-green"))
.start()
promise = $tgrepo.save($model.$modelValue)
promise.then ->
transform = $modelTransform.save (item) ->
item.is_blocked = true
item.blocked_note = $el.find(".reason").val()
return item
transform.then ->
$confirm.notify("success")
$rootscope.$broadcast("object:updated")
promise.then null, ->
transform.then null, ->
$confirm.notify("error")
item.revert()
$model.$setViewValue(item)
promise.finally ->
transform.finally ->
currentLoading.finish()
lightboxService.close($el)
@ -218,11 +222,7 @@ BlockLightboxDirective = ($rootscope, $tgrepo, $confirm, lightboxService, $loadi
lightboxService.open($el)
$scope.$on "unblock", (event, model, finishCallback) =>
item = $model.$modelValue.clone()
item.is_blocked = false
item.blocked_note = ""
unblock(item, finishCallback)
unblock(finishCallback)
$scope.$on "$destroy", ->
$el.off()
@ -230,11 +230,7 @@ BlockLightboxDirective = ($rootscope, $tgrepo, $confirm, lightboxService, $loadi
$el.on "click", ".button-green", (event) ->
event.preventDefault()
item = $model.$modelValue.clone()
item.is_blocked = true
item.blocked_note = $el.find(".reason").val()
block(item)
block()
return {
templateUrl: "common/lightbox/lightbox-block.html"
@ -242,7 +238,7 @@ BlockLightboxDirective = ($rootscope, $tgrepo, $confirm, lightboxService, $loadi
require: "ngModel"
}
module.directive("tgLbBlock", ["$rootScope", "$tgRepo", "$tgConfirm", "lightboxService", "$tgLoading", "$tgQqueue", "$translate", BlockLightboxDirective])
module.directive("tgLbBlock", ["$rootScope", "$tgRepo", "$tgConfirm", "lightboxService", "$tgLoading", "$tgQueueModelTransformation", "$translate", BlockLightboxDirective])
#############################################################################

View File

@ -222,7 +222,7 @@ module.directive("tgLbTagLine", ["$tgResources", "$tgTemplate", "$compile", LbTa
## TagLine Directive (for detail pages)
#############################################################################
TagLineDirective = ($rootScope, $repo, $rs, $confirm, $qqueue, $template, $compile) ->
TagLineDirective = ($rootScope, $repo, $rs, $confirm, $modelTransform, $template, $compile) ->
ENTER_KEY = 13
ESC_KEY = 27
COMMA_KEY = 188
@ -269,48 +269,49 @@ TagLineDirective = ($rootScope, $repo, $rs, $confirm, $qqueue, $template, $compi
autocomplete.close()
## Aux methods
addValue = $qqueue.bindAdd (value) ->
addValue = (value) ->
value = trim(value.toLowerCase())
return if value.length == 0
tags = _.clone($model.$modelValue.tags, false)
tags = [] if not tags?
tags.push(value) if value not in tags
transform = $modelTransform.save (item) ->
if not item.tags
item.tags = []
model = $model.$modelValue.clone()
model.tags = tags
$model.$setViewValue(model)
tags = _.clone(item.tags)
tags.push(value) if value not in tags
item.tags = tags
return item
onSuccess = ->
$rootScope.$broadcast("object:updated")
onError = ->
$confirm.notify("error")
model.revert()
$model.$setViewValue(model)
hideSaveButton()
return $repo.save(model).then(onSuccess, onError)
return transform.then(onSuccess, onError)
deleteValue = $qqueue.bindAdd (value) ->
deleteValue = (value) ->
value = trim(value.toLowerCase())
return if value.length == 0
tags = _.clone($model.$modelValue.tags, false)
tags = _.pull(tags, value)
transform = $modelTransform.save (item) ->
tags = _.clone(item.tags, false)
item.tags = _.pull(tags, value)
model = $model.$modelValue.clone()
model.tags = tags
$model.$setViewValue(model)
return item
onSuccess = ->
$rootScope.$broadcast("object:updated")
onError = ->
$confirm.notify("error")
model.revert()
$model.$setViewValue(model)
return $repo.save(model).then(onSuccess, onError)
return transform.then(onSuccess, onError)
saveInputTag = () ->
value = $el.find("input").val()
@ -374,7 +375,12 @@ TagLineDirective = ($rootScope, $repo, $rs, $confirm, $qqueue, $template, $compi
addValue(input.val())
input.val("")
$scope.$watch $attrs.ngModel, (model) ->
$scope.$watchCollection () ->
return $model.$modelValue?.tags
, () ->
model = $model.$modelValue
return if not model
if model.tags?.length
@ -394,5 +400,5 @@ TagLineDirective = ($rootScope, $repo, $rs, $confirm, $qqueue, $template, $compi
templateUrl: "common/tag/tag-line.html"
}
module.directive("tgTagLine", ["$rootScope", "$tgRepo", "$tgResources", "$tgConfirm", "$tgQqueue",
module.directive("tgTagLine", ["$rootScope", "$tgRepo", "$tgResources", "$tgConfirm", "$tgQueueModelTransformation",
"$tgTemplate", "$compile", TagLineDirective])

View File

@ -51,11 +51,12 @@ class IssueDetailController extends mixOf(taiga.Controller, taiga.PageMixin)
"tgAppMetaService",
"$tgAnalytics",
"$tgNavUrls",
"$translate"
"$translate",
"$tgQueueModelTransformation"
]
constructor: (@scope, @rootscope, @repo, @confirm, @rs, @params, @q, @location,
@log, @appMetaService, @analytics, @navUrls, @translate) ->
@log, @appMetaService, @analytics, @navUrls, @translate, @modelTransform) ->
bindMethods(@)
@scope.issueRef = @params.issueref
@ -130,6 +131,8 @@ class IssueDetailController extends mixOf(taiga.Controller, taiga.PageMixin)
@scope.issueId = issue.id
@scope.commentModel = issue
@modelTransform.setObject(@scope, 'issue')
if @scope.issue.neighbors.previous?.ref?
ctx = {
project: @scope.project.slug
@ -245,7 +248,7 @@ module.directive("tgIssueStatusDisplay", ["$tgTemplate", "$compile", IssueStatus
## Issue status button directive
#############################################################################
IssueStatusButtonDirective = ($rootScope, $repo, $confirm, $loading, $qqueue, $template, $compile) ->
IssueStatusButtonDirective = ($rootScope, $repo, $confirm, $loading, $modelTransform, $template, $compile) ->
# Display the status of Issue and you can edit it.
#
# Example:
@ -256,7 +259,7 @@ IssueStatusButtonDirective = ($rootScope, $repo, $confirm, $loading, $qqueue, $t
# - scope.statusById object
# - $scope.project.my_permissions
template = $template.get("issue/issues-status-button.html", true)
template = $template.get("common/components/status-button.html", true)
link = ($scope, $el, $attrs, $model) ->
isEditable = ->
@ -275,28 +278,27 @@ IssueStatusButtonDirective = ($rootScope, $repo, $confirm, $loading, $qqueue, $t
$el.html(html)
save = $qqueue.bindAdd (statusId) =>
save = (statusId) ->
$.fn.popover().closeAll()
issue = $model.$modelValue.clone()
issue.status = statusId
currentLoading = $loading()
.target($el)
.start()
transform = $modelTransform.save (issue) ->
issue.status = statusId
return issue
onSuccess = ->
$model.$setViewValue(issue)
$rootScope.$broadcast("object:updated")
currentLoading.finish()
onError = ->
$confirm.notify("error")
issue.revert()
$model.$setViewValue(issue)
currentLoading.finish()
$repo.save(issue).then(onSuccess, onError)
transform.then(onSuccess, onError)
$el.on "click", ".js-edit-status", (event) ->
event.preventDefault()
@ -314,7 +316,10 @@ IssueStatusButtonDirective = ($rootScope, $repo, $confirm, $loading, $qqueue, $t
save(target.data("status-id"))
$scope.$watch $attrs.ngModel, (issue) ->
$scope.$watch () ->
return $model.$modelValue?.status
, () ->
issue = $model.$modelValue
render(issue) if issue
$scope.$on "$destroy", ->
@ -326,13 +331,13 @@ IssueStatusButtonDirective = ($rootScope, $repo, $confirm, $loading, $qqueue, $t
require: "ngModel"
}
module.directive("tgIssueStatusButton", ["$rootScope", "$tgRepo", "$tgConfirm", "$tgLoading", "$tgQqueue", "$tgTemplate", "$compile", IssueStatusButtonDirective])
module.directive("tgIssueStatusButton", ["$rootScope", "$tgRepo", "$tgConfirm", "$tgLoading", "$tgQueueModelTransformation", "$tgTemplate", "$compile", IssueStatusButtonDirective])
#############################################################################
## Issue type button directive
#############################################################################
IssueTypeButtonDirective = ($rootScope, $repo, $confirm, $loading, $qqueue, $template, $compile) ->
IssueTypeButtonDirective = ($rootScope, $repo, $confirm, $loading, $modelTransform, $template, $compile) ->
# Display the type of Issue and you can edit it.
#
# Example:
@ -362,27 +367,27 @@ IssueTypeButtonDirective = ($rootScope, $repo, $confirm, $loading, $qqueue, $tem
$el.html(html)
save = $qqueue.bindAdd (type) =>
save = (type) ->
$.fn.popover().closeAll()
issue = $model.$modelValue.clone()
issue.type = type
currentLoading = $loading()
.target($el.find(".level-name"))
.start()
transform = $modelTransform.save (issue) ->
issue.type = type
return issue
onSuccess = ->
$model.$setViewValue(issue)
$rootScope.$broadcast("object:updated")
currentLoading.finish()
onError = ->
$confirm.notify("error")
issue.revert()
$model.$setViewValue(issue)
currentLoading.finish()
$repo.save(issue).then(onSuccess, onError)
transform.then(onSuccess, onError)
$el.on "click", ".type-data", (event) ->
event.preventDefault()
@ -400,7 +405,10 @@ IssueTypeButtonDirective = ($rootScope, $repo, $confirm, $loading, $qqueue, $tem
type = target.data("type-id")
save(type)
$scope.$watch $attrs.ngModel, (issue) ->
$scope.$watch () ->
return $model.$modelValue?.type
, () ->
issue = $model.$modelValue
render(issue) if issue
$scope.$on "$destroy", ->
@ -412,14 +420,14 @@ IssueTypeButtonDirective = ($rootScope, $repo, $confirm, $loading, $qqueue, $tem
require: "ngModel"
}
module.directive("tgIssueTypeButton", ["$rootScope", "$tgRepo", "$tgConfirm", "$tgLoading", "$tgQqueue", "$tgTemplate", "$compile", IssueTypeButtonDirective])
module.directive("tgIssueTypeButton", ["$rootScope", "$tgRepo", "$tgConfirm", "$tgLoading", "$tgQueueModelTransformation", "$tgTemplate", "$compile", IssueTypeButtonDirective])
#############################################################################
## Issue severity button directive
#############################################################################
IssueSeverityButtonDirective = ($rootScope, $repo, $confirm, $loading, $qqueue, $template, $compile) ->
IssueSeverityButtonDirective = ($rootScope, $repo, $confirm, $loading, $modelTransform, $template, $compile) ->
# Display the severity of Issue and you can edit it.
#
# Example:
@ -449,27 +457,27 @@ IssueSeverityButtonDirective = ($rootScope, $repo, $confirm, $loading, $qqueue,
$el.html(html)
save = $qqueue.bindAdd (severity) =>
save = (severity) ->
$.fn.popover().closeAll()
issue = $model.$modelValue.clone()
issue.severity = severity
currentLoading = $loading()
.target($el.find(".level-name"))
.start()
transform = $modelTransform.save (issue) ->
issue.severity = severity
return issue
onSuccess = ->
$model.$setViewValue(issue)
$rootScope.$broadcast("object:updated")
currentLoading.finish()
onError = ->
$confirm.notify("error")
issue.revert()
$model.$setViewValue(issue)
currentLoading.finish()
$repo.save(issue).then(onSuccess, onError)
transform.then(onSuccess, onError)
$el.on "click", ".severity-data", (event) ->
event.preventDefault()
@ -488,7 +496,10 @@ IssueSeverityButtonDirective = ($rootScope, $repo, $confirm, $loading, $qqueue,
save(severity)
$scope.$watch $attrs.ngModel, (issue) ->
$scope.$watch () ->
return $model.$modelValue?.severity
, () ->
issue = $model.$modelValue
render(issue) if issue
$scope.$on "$destroy", ->
@ -500,14 +511,14 @@ IssueSeverityButtonDirective = ($rootScope, $repo, $confirm, $loading, $qqueue,
require: "ngModel"
}
module.directive("tgIssueSeverityButton", ["$rootScope", "$tgRepo", "$tgConfirm", "$tgLoading", "$tgQqueue", "$tgTemplate", "$compile", IssueSeverityButtonDirective])
module.directive("tgIssueSeverityButton", ["$rootScope", "$tgRepo", "$tgConfirm", "$tgLoading", "$tgQueueModelTransformation", "$tgTemplate", "$compile", IssueSeverityButtonDirective])
#############################################################################
## Issue priority button directive
#############################################################################
IssuePriorityButtonDirective = ($rootScope, $repo, $confirm, $loading, $qqueue, $template, $compile) ->
IssuePriorityButtonDirective = ($rootScope, $repo, $confirm, $loading, $modelTransform, $template, $compile) ->
# Display the priority of Issue and you can edit it.
#
# Example:
@ -537,27 +548,27 @@ IssuePriorityButtonDirective = ($rootScope, $repo, $confirm, $loading, $qqueue,
$el.html(html)
save = $qqueue.bindAdd (priority) =>
save = (priority) ->
$.fn.popover().closeAll()
issue = $model.$modelValue.clone()
issue.priority = priority
currentLoading = $loading()
.target($el.find(".level-name"))
.start()
transform = $modelTransform.save (issue) ->
issue.priority = priority
return issue
onSuccess = ->
$model.$setViewValue(issue)
$rootScope.$broadcast("object:updated")
currentLoading.finish()
onError = ->
$confirm.notify("error")
issue.revert()
$model.$setViewValue(issue)
currentLoading.finish()
$repo.save(issue).then(onSuccess, onError)
transform.then(onSuccess, onError)
$el.on "click", ".priority-data", (event) ->
event.preventDefault()
@ -576,7 +587,10 @@ IssuePriorityButtonDirective = ($rootScope, $repo, $confirm, $loading, $qqueue,
save(priority)
$scope.$watch $attrs.ngModel, (issue) ->
$scope.$watch () ->
return $model.$modelValue?.priority
, () ->
issue = $model.$modelValue
render(issue) if issue
$scope.$on "$destroy", ->
@ -588,17 +602,17 @@ IssuePriorityButtonDirective = ($rootScope, $repo, $confirm, $loading, $qqueue,
require: "ngModel"
}
module.directive("tgIssuePriorityButton", ["$rootScope", "$tgRepo", "$tgConfirm", "$tgLoading", "$tgQqueue", "$tgTemplate", "$compile", IssuePriorityButtonDirective])
module.directive("tgIssuePriorityButton", ["$rootScope", "$tgRepo", "$tgConfirm", "$tgLoading", "$tgQueueModelTransformation", "$tgTemplate", "$compile", IssuePriorityButtonDirective])
#############################################################################
## Promote Issue to US button directive
#############################################################################
PromoteIssueToUsButtonDirective = ($rootScope, $repo, $confirm, $qqueue, $translate) ->
PromoteIssueToUsButtonDirective = ($rootScope, $repo, $confirm, $translate) ->
link = ($scope, $el, $attrs, $model) ->
save = $qqueue.bindAdd (issue, askResponse) =>
save = (issue, askResponse) =>
data = {
generated_from_issue: issue.id
project: issue.project,
@ -620,7 +634,6 @@ PromoteIssueToUsButtonDirective = ($rootScope, $repo, $confirm, $qqueue, $transl
$repo.create("userstories", data).then(onSuccess, onError)
$el.on "click", "a", (event) ->
event.preventDefault()
issue = $model.$modelValue
@ -642,5 +655,5 @@ PromoteIssueToUsButtonDirective = ($rootScope, $repo, $confirm, $qqueue, $transl
link: link
}
module.directive("tgPromoteIssueToUsButton", ["$rootScope", "$tgRepo", "$tgConfirm", "$tgQqueue", "$translate"
module.directive("tgPromoteIssueToUsButton", ["$rootScope", "$tgRepo", "$tgConfirm", "$translate"
PromoteIssueToUsButtonDirective])

View File

@ -49,11 +49,12 @@ class TaskDetailController extends mixOf(taiga.Controller, taiga.PageMixin)
"tgAppMetaService",
"$tgNavUrls",
"$tgAnalytics",
"$translate"
"$translate",
"$tgQueueModelTransformation"
]
constructor: (@scope, @rootscope, @repo, @confirm, @rs, @params, @q, @location,
@log, @appMetaService, @navUrls, @analytics, @translate) ->
@log, @appMetaService, @navUrls, @analytics, @translate, @modelTransform) ->
bindMethods(@)
@scope.taskRef = @params.taskref
@ -118,6 +119,8 @@ class TaskDetailController extends mixOf(taiga.Controller, taiga.PageMixin)
@scope.taskId = task.id
@scope.commentModel = task
@modelTransform.setObject(@scope, 'task')
if @scope.task.neighbors.previous?.ref?
ctx = {
project: @scope.project.slug
@ -245,7 +248,7 @@ module.directive("tgTaskStatusDisplay", ["$tgTemplate", "$compile", TaskStatusDi
## Task status button directive
#############################################################################
TaskStatusButtonDirective = ($rootScope, $repo, $confirm, $loading, $qqueue, $compile, $translate, $template) ->
TaskStatusButtonDirective = ($rootScope, $repo, $confirm, $loading, $modelTransform, $compile, $translate, $template) ->
# Display the status of Task and you can edit it.
#
# Example:
@ -256,7 +259,7 @@ TaskStatusButtonDirective = ($rootScope, $repo, $confirm, $loading, $qqueue, $co
# - scope.statusById object
# - $scope.project.my_permissions
template = $template.get("us/us-status-button.html", true)
template = $template.get("common/components/status-button.html", true)
link = ($scope, $el, $attrs, $model) ->
isEditable = ->
@ -273,16 +276,17 @@ TaskStatusButtonDirective = ($rootScope, $repo, $confirm, $loading, $qqueue, $co
$el.html(html)
save = $qqueue.bindAdd (status) =>
task = $model.$modelValue.clone()
task.status = status
save = (status) ->
currentLoading = $loading()
.target($el)
.start()
transform = $modelTransform.save (task) ->
task.status = status
return task
onSuccess = ->
$model.$setViewValue(task)
$rootScope.$broadcast("object:updated")
currentLoading.finish()
@ -290,7 +294,7 @@ TaskStatusButtonDirective = ($rootScope, $repo, $confirm, $loading, $qqueue, $co
$confirm.notify("error")
currentLoading.finish()
$repo.save(task).then(onSuccess, onError)
transform.then(onSuccess, onError)
$el.on "click", ".js-edit-status", (event) ->
event.preventDefault()
@ -310,7 +314,10 @@ TaskStatusButtonDirective = ($rootScope, $repo, $confirm, $loading, $qqueue, $co
save(target.data("status-id"))
$scope.$watch $attrs.ngModel, (task) ->
$scope.$watch () ->
return $model.$modelValue?.status
, () ->
task = $model.$modelValue
render(task) if task
$scope.$on "$destroy", ->
@ -322,11 +329,11 @@ TaskStatusButtonDirective = ($rootScope, $repo, $confirm, $loading, $qqueue, $co
require: "ngModel"
}
module.directive("tgTaskStatusButton", ["$rootScope", "$tgRepo", "$tgConfirm", "$tgLoading", "$tgQqueue",
module.directive("tgTaskStatusButton", ["$rootScope", "$tgRepo", "$tgConfirm", "$tgLoading", "$tgQueueModelTransformation",
"$compile", "$translate", "$tgTemplate", TaskStatusButtonDirective])
TaskIsIocaineButtonDirective = ($rootscope, $tgrepo, $confirm, $loading, $qqueue, $compile, $template) ->
TaskIsIocaineButtonDirective = ($rootscope, $tgrepo, $confirm, $loading, $modelTransform, $compile, $template) ->
template = $template.get("issue/iocaine-button.html", true)
link = ($scope, $el, $attrs, $model) ->
@ -345,24 +352,23 @@ TaskIsIocaineButtonDirective = ($rootscope, $tgrepo, $confirm, $loading, $qqueue
html = $compile(template(ctx))($scope)
$el.html(html)
save = $qqueue.bindAdd (is_iocaine) =>
task = $model.$modelValue.clone()
task.is_iocaine = is_iocaine
save = (is_iocaine) ->
currentLoading = $loading()
.target($el.find('label'))
.start()
promise = $tgrepo.save(task)
transform = $modelTransform.save (task) ->
task.is_iocaine = is_iocaine
promise.then ->
$model.$setViewValue(task)
return task
transform.then ->
$rootscope.$broadcast("object:updated")
promise.then null, ->
transform.then null, ->
$confirm.notify("error")
promise.finally ->
transform.finally ->
currentLoading.finish()
$el.on "click", ".is-iocaine", (event) ->
@ -371,7 +377,10 @@ TaskIsIocaineButtonDirective = ($rootscope, $tgrepo, $confirm, $loading, $qqueue
is_iocaine = not $model.$modelValue.is_iocaine
save(is_iocaine)
$scope.$watch $attrs.ngModel, (task) ->
$scope.$watch () ->
return $model.$modelValue?.is_iocaine
, () ->
task = $model.$modelValue
render(task) if task
$scope.$on "$destroy", ->
@ -383,5 +392,5 @@ TaskIsIocaineButtonDirective = ($rootscope, $tgrepo, $confirm, $loading, $qqueue
require: "ngModel"
}
module.directive("tgTaskIsIocaineButton", ["$rootScope", "$tgRepo", "$tgConfirm", "$tgLoading", "$tgQqueue",
module.directive("tgTaskIsIocaineButton", ["$rootScope", "$tgRepo", "$tgConfirm", "$tgLoading", "$tgQueueModelTransformation",
"$compile", "$tgTemplate", TaskIsIocaineButtonDirective])

View File

@ -49,11 +49,12 @@ class UserStoryDetailController extends mixOf(taiga.Controller, taiga.PageMixin)
"tgAppMetaService",
"$tgNavUrls",
"$tgAnalytics",
"$translate"
"$translate",
"$tgQueueModelTransformation"
]
constructor: (@scope, @rootscope, @repo, @confirm, @rs, @params, @q, @location,
@log, @appMetaService, @navUrls, @analytics, @translate) ->
@log, @appMetaService, @navUrls, @analytics, @translate, @modelTransform) ->
bindMethods(@)
@scope.usRef = @params.usref
@ -159,6 +160,8 @@ class UserStoryDetailController extends mixOf(taiga.Controller, taiga.PageMixin)
@scope.usId = us.id
@scope.commentModel = us
@modelTransform.setObject(@scope, 'us')
if @scope.us.neighbors.previous?.ref?
ctx = {
project: @scope.project.slug
@ -285,7 +288,7 @@ module.directive("tgUsStatusDisplay", ["$tgTemplate", "$compile", UsStatusDispla
## User story status button directive
#############################################################################
UsStatusButtonDirective = ($rootScope, $repo, $confirm, $loading, $qqueue, $template) ->
UsStatusButtonDirective = ($rootScope, $repo, $confirm, $loading, $modelTransform, $template, $compile) ->
# Display the status of a US and you can edit it.
#
# Example:
@ -296,7 +299,7 @@ UsStatusButtonDirective = ($rootScope, $repo, $confirm, $loading, $qqueue, $temp
# - scope.statusById object
# - $scope.project.my_permissions
template = $template.get("us/us-status-button.html", true)
template = $template.get("common/components/status-button.html", true)
link = ($scope, $el, $attrs, $model) ->
isEditable = ->
@ -313,19 +316,21 @@ UsStatusButtonDirective = ($rootScope, $repo, $confirm, $loading, $qqueue, $temp
$el.html(html)
save = $qqueue.bindAdd (status) =>
us = $model.$modelValue.clone()
$compile($el.contents())($scope);
us.status = status
$.fn.popover().closeAll()
save = (status) =>
$el.find(".pop-status").popover().close()
currentLoading = $loading()
.target($el)
.target($el.find('.js-edit-status'))
.start()
transform = $modelTransform.save (us) ->
us.status = status
return us
onSuccess = ->
$model.$setViewValue(us)
$rootScope.$broadcast("object:updated")
currentLoading.finish()
@ -333,7 +338,7 @@ UsStatusButtonDirective = ($rootScope, $repo, $confirm, $loading, $qqueue, $temp
$confirm.notify("error")
currentLoading.finish()
$repo.save(us).then(onSuccess, onError)
transform.then(onSuccess, onError)
$el.on "click", ".js-edit-status", (event) ->
event.preventDefault()
@ -352,7 +357,11 @@ UsStatusButtonDirective = ($rootScope, $repo, $confirm, $loading, $qqueue, $temp
save(status)
$scope.$watch $attrs.ngModel, (us) ->
$scope.$watch () ->
return $model.$modelValue?.status
, () ->
us = $model.$modelValue
render(us) if us
$scope.$on "$destroy", ->
@ -364,7 +373,7 @@ UsStatusButtonDirective = ($rootScope, $repo, $confirm, $loading, $qqueue, $temp
require: "ngModel"
}
module.directive("tgUsStatusButton", ["$rootScope", "$tgRepo", "$tgConfirm", "$tgLoading","$tgQqueue", "$tgTemplate",
module.directive("tgUsStatusButton", ["$rootScope", "$tgRepo", "$tgConfirm", "$tgLoading","$tgQueueModelTransformation", "$tgTemplate", "$compile",
UsStatusButtonDirective])
@ -372,7 +381,7 @@ module.directive("tgUsStatusButton", ["$rootScope", "$tgRepo", "$tgConfirm", "$t
## User story team requirements button directive
#############################################################################
UsTeamRequirementButtonDirective = ($rootscope, $tgrepo, $confirm, $loading, $qqueue, $template, $compile) ->
UsTeamRequirementButtonDirective = ($rootscope, $tgrepo, $confirm, $loading, $modelTransform, $template, $compile) ->
template = $template.get("us/us-team-requirement-button.html", true)
link = ($scope, $el, $attrs, $model) ->
@ -389,21 +398,21 @@ UsTeamRequirementButtonDirective = ($rootscope, $tgrepo, $confirm, $loading, $qq
$el.html(html)
save = $qqueue.bindAdd (team_requirement) =>
us = $model.$modelValue.clone()
us.team_requirement = team_requirement
save = (team_requirement) ->
currentLoading = $loading()
.target($el.find("label"))
.start()
promise = $tgrepo.save(us)
promise.then =>
$model.$setViewValue(us)
transform = $modelTransform.save (us) ->
us.team_requirement = team_requirement
return us
transform.then =>
currentLoading.finish()
$rootscope.$broadcast("object:updated")
promise.then null, ->
transform.then null, ->
currentLoading.finish()
$confirm.notify("error")
@ -414,7 +423,11 @@ UsTeamRequirementButtonDirective = ($rootscope, $tgrepo, $confirm, $loading, $qq
save(team_requirement)
$scope.$watch $attrs.ngModel, (us) ->
$scope.$watch () ->
return $model.$modelValue?.team_requirement
, () ->
us = $model.$modelValue
render(us) if us
$scope.$on "$destroy", ->
@ -426,13 +439,13 @@ UsTeamRequirementButtonDirective = ($rootscope, $tgrepo, $confirm, $loading, $qq
require: "ngModel"
}
module.directive("tgUsTeamRequirementButton", ["$rootScope", "$tgRepo", "$tgConfirm", "$tgLoading", "$tgQqueue", "$tgTemplate", "$compile", UsTeamRequirementButtonDirective])
module.directive("tgUsTeamRequirementButton", ["$rootScope", "$tgRepo", "$tgConfirm", "$tgLoading", "$tgQueueModelTransformation", "$tgTemplate", "$compile", UsTeamRequirementButtonDirective])
#############################################################################
## User story client requirements button directive
#############################################################################
UsClientRequirementButtonDirective = ($rootscope, $tgrepo, $confirm, $loading, $qqueue, $template, $compile) ->
UsClientRequirementButtonDirective = ($rootscope, $tgrepo, $confirm, $loading, $modelTransform, $template, $compile) ->
template = $template.get("us/us-client-requirement-button.html", true)
link = ($scope, $el, $attrs, $model) ->
@ -447,21 +460,21 @@ UsClientRequirementButtonDirective = ($rootscope, $tgrepo, $confirm, $loading, $
html = $compile(template(ctx))($scope)
$el.html(html)
save = $qqueue.bindAdd (client_requirement) =>
us = $model.$modelValue.clone()
us.client_requirement = client_requirement
save = (client_requirement) ->
currentLoading = $loading()
.target($el.find("label"))
.start()
promise = $tgrepo.save(us)
promise.then =>
$model.$setViewValue(us)
transform = $modelTransform.save (us) ->
us.client_requirement = client_requirement
return us
transform.then =>
currentLoading.finish()
$rootscope.$broadcast("object:updated")
promise.then null, ->
transform.then null, ->
$confirm.notify("error")
$el.on "click", ".client-requirement", (event) ->
@ -470,7 +483,10 @@ UsClientRequirementButtonDirective = ($rootscope, $tgrepo, $confirm, $loading, $
client_requirement = not $model.$modelValue.client_requirement
save(client_requirement)
$scope.$watch $attrs.ngModel, (us) ->
$scope.$watch () ->
return $model.$modelValue?.client_requirement
, () ->
us = $model.$modelValue
render(us) if us
$scope.$on "$destroy", ->
@ -482,5 +498,5 @@ UsClientRequirementButtonDirective = ($rootscope, $tgrepo, $confirm, $loading, $
require: "ngModel"
}
module.directive("tgUsClientRequirementButton", ["$rootScope", "$tgRepo", "$tgConfirm", "$tgLoading", "$tgQqueue", "$tgTemplate", "$compile",
module.directive("tgUsClientRequirementButton", ["$rootScope", "$tgRepo", "$tgConfirm", "$tgLoading", "$tgQueueModelTransformation", "$tgTemplate", "$compile",
UsClientRequirementButtonDirective])

View File

@ -0,0 +1,19 @@
span.detail-status-inner.js-edit-status(
class!="<% if(editable){ %>clickable<% }%>"
)
span(style!="background-color:<%- status.color %>")
span.e2e-status <%- status.name %>
<% if(editable){ %>
tg-svg(svg-icon="icon-arrow-down")
<% }%>
ul.pop-status.popover
<% _.each(statuses, function(st) { %>
li
a.status(
href=""
title!="<%- st.name %>"
data-status-id!="<%- st.id %>"
)
| <%- st.name %>
<% }); %>

View File

@ -1,20 +0,0 @@
span.detail-status-inner.js-edit-status(
class!="<% if(editable){ %>clickable<% }%>"
style!="background-color:<%- status.color %>"
ng-click="editStatus()"
)
span <%- status.name %>
<% if(editable){ %>
tg-svg(svg-icon="icon-arrow-down")
<% }%>
ul.popover.pop-status
<% _.each(statuses, function(st) { %>
li
a.status(
href=""
title!="<%- st.name %>"
data-status-id!="<%- st.id %>"
)
| <%- st.name %>
<% }); %>

View File

@ -96,7 +96,7 @@ div.wrapper(
)
sidebar.menu-secondary.sidebar.ticket-data
section.ticket-header
span.ticket-title(
tg-us-status-display

View File

@ -1,19 +0,0 @@
span.detail-status-inner.js-edit-status(
class!="<% if(editable){ %>clickable<% }%>"
style!="background-color:<%- status.color %>"
)
span <%- status.name %>
<% if(editable){ %>
tg-svg(svg-icon="icon-arrow-down")
<% }%>
ul.pop-status.popover
<% _.each(statuses, function(st) { %>
li
a.status(
href=""
title!="<%- st.name %>"
data-status-id!="<%- st.id %>"
)
| <%- st.name %>
<% }); %>

View File

@ -22,11 +22,13 @@
}
.detail-status-inner {
align-items: center;
color: $white;
display: flex;
justify-content: flex-start;
padding: .15rem .25rem;
text-transform: uppercase;
> span {
color: $white;
padding: .15rem .25rem;
text-transform: uppercase;
}
}
.pop-status {
@include popover(150px, 1.25rem, 0, '', '');

View File

@ -107,7 +107,7 @@ helper.statusSelector = function() {
return this.getSelectedStatus();
},
getSelectedStatus: async function(){
return el.$$('.detail-status-inner span').first().getInnerHtml();
return el.$$('.detail-status-inner .e2e-status').first().getInnerHtml();
}
};