Merge pull request #1138 from taigaio/issue/4417/crazy-dates
add an independent object in the sprint form and destroy datapicker e…stable
commit
90e37b940b
|
@ -37,11 +37,12 @@ CreateEditSprint = ($repo, $confirm, $rs, $rootscope, lightboxService, $loading,
|
||||||
hasErrors = false
|
hasErrors = false
|
||||||
createSprint = true
|
createSprint = true
|
||||||
form = null
|
form = null
|
||||||
|
$scope.newSprint = {}
|
||||||
|
|
||||||
resetSprint = () ->
|
resetSprint = () ->
|
||||||
form.reset() if form
|
form.reset() if form
|
||||||
|
|
||||||
$scope.sprint = {
|
$scope.newSprint = {
|
||||||
project: null
|
project: null
|
||||||
name: null
|
name: null
|
||||||
estimated_start: null
|
estimated_start: null
|
||||||
|
@ -62,19 +63,23 @@ CreateEditSprint = ($repo, $confirm, $rs, $rootscope, lightboxService, $loading,
|
||||||
return
|
return
|
||||||
|
|
||||||
hasErrors = false
|
hasErrors = false
|
||||||
newSprint = angular.copy($scope.sprint)
|
|
||||||
broadcastEvent = null
|
broadcastEvent = null
|
||||||
|
|
||||||
|
estimated_start = $('.date-start').val()
|
||||||
|
estimated_end = $('.date-end').val()
|
||||||
|
|
||||||
if createSprint
|
if createSprint
|
||||||
newSprint.estimated_start = moment(newSprint.estimated_start, prettyDate).format("YYYY-MM-DD")
|
newSprint = angular.copy($scope.newSprint)
|
||||||
newSprint.estimated_finish = moment(newSprint.estimated_finish,prettyDate).format("YYYY-MM-DD")
|
newSprint.estimated_start = moment(estimated_start, prettyDate).format("YYYY-MM-DD")
|
||||||
|
newSprint.estimated_finish = moment(estimated_end, prettyDate).format("YYYY-MM-DD")
|
||||||
|
|
||||||
promise = $repo.create("milestones", newSprint)
|
promise = $repo.create("milestones", newSprint)
|
||||||
broadcastEvent = "sprintform:create:success"
|
broadcastEvent = "sprintform:create:success"
|
||||||
else
|
else
|
||||||
newSprint.setAttr("estimated_start",
|
newSprint = $scope.newSprint.realClone()
|
||||||
moment(newSprint.estimated_start, prettyDate).format("YYYY-MM-DD"))
|
newSprint.estimated_start = moment(estimated_start, prettyDate).format("YYYY-MM-DD")
|
||||||
newSprint.setAttr("estimated_finish",
|
newSprint.estimated_finish = moment(estimated_end, prettyDate).format("YYYY-MM-DD")
|
||||||
moment(newSprint.estimated_finish, prettyDate).format("YYYY-MM-DD"))
|
|
||||||
promise = $repo.save(newSprint)
|
promise = $repo.save(newSprint)
|
||||||
broadcastEvent = "sprintform:edit:success"
|
broadcastEvent = "sprintform:edit:success"
|
||||||
|
|
||||||
|
@ -85,6 +90,13 @@ CreateEditSprint = ($repo, $confirm, $rs, $rootscope, lightboxService, $loading,
|
||||||
promise.then (data) ->
|
promise.then (data) ->
|
||||||
currentLoading.finish()
|
currentLoading.finish()
|
||||||
$scope.sprintsCounter += 1 if createSprint
|
$scope.sprintsCounter += 1 if createSprint
|
||||||
|
|
||||||
|
$scope.sprints = _.map $scope.sprints, (it) ->
|
||||||
|
if it.id == data.id
|
||||||
|
return data
|
||||||
|
else
|
||||||
|
return it
|
||||||
|
|
||||||
$rootscope.$broadcast(broadcastEvent, data)
|
$rootscope.$broadcast(broadcastEvent, data)
|
||||||
|
|
||||||
lightboxService.close($el)
|
lightboxService.close($el)
|
||||||
|
@ -100,19 +112,19 @@ CreateEditSprint = ($repo, $confirm, $rs, $rootscope, lightboxService, $loading,
|
||||||
|
|
||||||
remove = ->
|
remove = ->
|
||||||
title = $translate.instant("LIGHTBOX.DELETE_SPRINT.TITLE")
|
title = $translate.instant("LIGHTBOX.DELETE_SPRINT.TITLE")
|
||||||
message = $scope.sprint.name
|
message = $scope.newSprint.name
|
||||||
|
|
||||||
$confirm.askOnDelete(title, message).then (askResponse) =>
|
$confirm.askOnDelete(title, message).then (askResponse) =>
|
||||||
onSuccess = ->
|
onSuccess = ->
|
||||||
askResponse.finish()
|
askResponse.finish()
|
||||||
$scope.milestonesCounter -= 1
|
$scope.milestonesCounter -= 1
|
||||||
lightboxService.close($el)
|
lightboxService.close($el)
|
||||||
$rootscope.$broadcast("sprintform:remove:success", $scope.sprint)
|
$rootscope.$broadcast("sprintform:remove:success", $scope.newSprint)
|
||||||
|
|
||||||
onError = ->
|
onError = ->
|
||||||
askResponse.finish(false)
|
askResponse.finish(false)
|
||||||
$confirm.notify("error")
|
$confirm.notify("error")
|
||||||
$repo.remove($scope.sprint).then(onSuccess, onError)
|
$repo.remove($scope.newSprint).then(onSuccess, onError)
|
||||||
|
|
||||||
getLastSprint = ->
|
getLastSprint = ->
|
||||||
openSprints = _.filter $scope.sprints, (sprint) ->
|
openSprints = _.filter $scope.sprints, (sprint) ->
|
||||||
|
@ -131,9 +143,9 @@ CreateEditSprint = ($repo, $confirm, $rs, $rootscope, lightboxService, $loading,
|
||||||
|
|
||||||
createSprint = true
|
createSprint = true
|
||||||
prettyDate = $translate.instant("COMMON.PICKERDATE.FORMAT")
|
prettyDate = $translate.instant("COMMON.PICKERDATE.FORMAT")
|
||||||
$scope.sprint.project = projectId
|
$scope.newSprint.project = projectId
|
||||||
$scope.sprint.name = null
|
$scope.newSprint.name = null
|
||||||
$scope.sprint.slug = null
|
$scope.newSprint.slug = null
|
||||||
|
|
||||||
lastSprint = getLastSprint()
|
lastSprint = getLastSprint()
|
||||||
|
|
||||||
|
@ -141,19 +153,19 @@ CreateEditSprint = ($repo, $confirm, $rs, $rootscope, lightboxService, $loading,
|
||||||
|
|
||||||
if lastSprint
|
if lastSprint
|
||||||
estimatedStart = moment(lastSprint.estimated_finish)
|
estimatedStart = moment(lastSprint.estimated_finish)
|
||||||
else if $scope.sprint.estimated_start
|
else if $scope.newSprint.estimated_start
|
||||||
estimatedStart = moment($scope.sprint.estimated_start)
|
estimatedStart = moment($scope.newSprint.estimated_start)
|
||||||
|
|
||||||
$scope.sprint.estimated_start = estimatedStart.format(prettyDate)
|
$scope.newSprint.estimated_start = estimatedStart.format(prettyDate)
|
||||||
|
|
||||||
estimatedFinish = moment().add(2, "weeks")
|
estimatedFinish = moment().add(2, "weeks")
|
||||||
|
|
||||||
if lastSprint
|
if lastSprint
|
||||||
estimatedFinish = moment(lastSprint.estimated_finish).add(2, "weeks")
|
estimatedFinish = moment(lastSprint.estimated_finish).add(2, "weeks")
|
||||||
else if $scope.sprint.estimated_finish
|
else if $scope.newSprint.estimated_finish
|
||||||
estimatedFinish = moment($scope.sprint.estimated_finish)
|
estimatedFinish = moment($scope.newSprint.estimated_finish)
|
||||||
|
|
||||||
$scope.sprint.estimated_finish = estimatedFinish.format(prettyDate)
|
$scope.newSprint.estimated_finish = estimatedFinish.format(prettyDate)
|
||||||
|
|
||||||
lastSprintNameDom = $el.find(".last-sprint-name")
|
lastSprintNameDom = $el.find(".last-sprint-name")
|
||||||
if lastSprint?.name?
|
if lastSprint?.name?
|
||||||
|
@ -179,10 +191,10 @@ CreateEditSprint = ($repo, $confirm, $rs, $rootscope, lightboxService, $loading,
|
||||||
createSprint = false
|
createSprint = false
|
||||||
prettyDate = $translate.instant("COMMON.PICKERDATE.FORMAT")
|
prettyDate = $translate.instant("COMMON.PICKERDATE.FORMAT")
|
||||||
|
|
||||||
$scope.$apply ->
|
$scope.$apply () ->
|
||||||
$scope.sprint = sprint
|
$scope.newSprint = sprint.realClone()
|
||||||
$scope.sprint.estimated_start = moment($scope.sprint.estimated_start).format(prettyDate)
|
$scope.newSprint.estimated_start = moment($scope.newSprint.estimated_start).format(prettyDate)
|
||||||
$scope.sprint.estimated_finish = moment($scope.sprint.estimated_finish).format(prettyDate)
|
$scope.newSprint.estimated_finish = moment($scope.newSprint.estimated_finish).format(prettyDate)
|
||||||
|
|
||||||
$el.find(".delete-sprint").removeClass("hidden")
|
$el.find(".delete-sprint").removeClass("hidden")
|
||||||
|
|
||||||
|
|
|
@ -239,7 +239,7 @@ class BacklogController extends mixOf(taiga.Controller, taiga.PageMixin, taiga.F
|
||||||
sprint.user_stories = _.sortBy(sprint.user_stories, "sprint_order")
|
sprint.user_stories = _.sortBy(sprint.user_stories, "sprint_order")
|
||||||
|
|
||||||
@scope.sprints = sprints
|
@scope.sprints = sprints
|
||||||
@scope.openSprints = _.filter(sprints, (sprint) => not sprint.closed).reverse()
|
|
||||||
@scope.closedSprints = [] if !@scope.closedSprints
|
@scope.closedSprints = [] if !@scope.closedSprints
|
||||||
|
|
||||||
@scope.sprintsCounter = sprints.length
|
@scope.sprintsCounter = sprints.length
|
||||||
|
@ -250,6 +250,9 @@ class BacklogController extends mixOf(taiga.Controller, taiga.PageMixin, taiga.F
|
||||||
|
|
||||||
return sprints
|
return sprints
|
||||||
|
|
||||||
|
openSprints: ->
|
||||||
|
return _.filter(@scope.sprints, (sprint) => not sprint.closed).reverse()
|
||||||
|
|
||||||
loadAllPaginatedUserstories: () ->
|
loadAllPaginatedUserstories: () ->
|
||||||
page = @.page
|
page = @.page
|
||||||
|
|
||||||
|
|
|
@ -98,6 +98,7 @@ BacklogSprintHeaderDirective = ($navUrls, $template, $compile, $translate) ->
|
||||||
|
|
||||||
start = moment(sprint.estimated_start).format(prettyDate)
|
start = moment(sprint.estimated_start).format(prettyDate)
|
||||||
finish = moment(sprint.estimated_finish).format(prettyDate)
|
finish = moment(sprint.estimated_finish).format(prettyDate)
|
||||||
|
|
||||||
estimatedDateRange = "#{start}-#{finish}"
|
estimatedDateRange = "#{start}-#{finish}"
|
||||||
|
|
||||||
ctx = {
|
ctx = {
|
||||||
|
@ -117,19 +118,15 @@ BacklogSprintHeaderDirective = ($navUrls, $template, $compile, $translate) ->
|
||||||
compiledTemplate = $compile(template)(templateScope)
|
compiledTemplate = $compile(template)(templateScope)
|
||||||
$el.html(compiledTemplate)
|
$el.html(compiledTemplate)
|
||||||
|
|
||||||
$scope.$watch $attrs.ngModel, (sprint) ->
|
$scope.$watch "sprint", (sprint) ->
|
||||||
render(sprint)
|
render(sprint)
|
||||||
|
|
||||||
$scope.$on "sprintform:edit:success", ->
|
|
||||||
render($model.$modelValue)
|
|
||||||
|
|
||||||
$scope.$on "$destroy", ->
|
$scope.$on "$destroy", ->
|
||||||
$el.off()
|
$el.off()
|
||||||
|
|
||||||
return {
|
return {
|
||||||
link: link
|
link: link
|
||||||
restrict: "EA"
|
restrict: "EA"
|
||||||
require: "ngModel"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.directive("tgBacklogSprintHeader", ["$tgNavUrls", "$tgTemplate", "$compile", "$translate"
|
module.directive("tgBacklogSprintHeader", ["$tgNavUrls", "$tgTemplate", "$compile", "$translate"
|
||||||
|
|
|
@ -31,6 +31,16 @@ class Model
|
||||||
@.setAttrs(data)
|
@.setAttrs(data)
|
||||||
@.initialize()
|
@.initialize()
|
||||||
|
|
||||||
|
realClone: ->
|
||||||
|
attrs = _.cloneDeep(@._attrs)
|
||||||
|
|
||||||
|
instance = new Model(@._name, attrs, @._dataTypes)
|
||||||
|
|
||||||
|
instance._modifiedAttrs = _.cloneDeep(@._modifiedAttrs)
|
||||||
|
instance._isModified = _.cloneDeep(@._isModified)
|
||||||
|
|
||||||
|
return instance
|
||||||
|
|
||||||
clone: ->
|
clone: ->
|
||||||
instance = new Model(@._name, @._attrs, @._dataTypes)
|
instance = new Model(@._name, @._attrs, @._dataTypes)
|
||||||
instance._modifiedAttrs = @._modifiedAttrs
|
instance._modifiedAttrs = @._modifiedAttrs
|
||||||
|
|
|
@ -64,27 +64,30 @@ DateSelectorDirective = ($rootscope, datePickerConfigService) ->
|
||||||
|
|
||||||
_.merge(datePickerConfig, {
|
_.merge(datePickerConfig, {
|
||||||
field: $el[0]
|
field: $el[0]
|
||||||
onSelect: (date) =>
|
|
||||||
selectedDate = date
|
|
||||||
onOpen: =>
|
|
||||||
$el.picker.setDate(selectedDate) if selectedDate?
|
|
||||||
})
|
})
|
||||||
|
|
||||||
$el.picker = new Pikaday(datePickerConfig)
|
$el.picker = new Pikaday(datePickerConfig)
|
||||||
|
|
||||||
unbind = $rootscope.$on "$translateChangeEnd", (ctx) => initialize()
|
unbind = $rootscope.$on "$translateChangeEnd", (ctx) =>
|
||||||
|
$el.picker.destroy() if $el.picker
|
||||||
|
initialize()
|
||||||
|
|
||||||
$scope.$watch $attrs.ngModel, (val) ->
|
$attrs.$observe "pickerValue", (val) ->
|
||||||
initialize() if val? and not $el.picker
|
$el.val(val)
|
||||||
$el.picker.setDate(val) if val?
|
|
||||||
|
if val?
|
||||||
|
$el.picker.destroy() if $el.picker
|
||||||
|
initialize()
|
||||||
|
|
||||||
|
$el.picker.setDate(val)
|
||||||
|
|
||||||
$scope.$on "$destroy", ->
|
$scope.$on "$destroy", ->
|
||||||
$el.off()
|
$el.off()
|
||||||
unbind()
|
unbind()
|
||||||
|
$el.picker.destroy()
|
||||||
|
|
||||||
return {
|
return {
|
||||||
link: link
|
link: link
|
||||||
require: "ngModel"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.directive("tgDateSelector", ["$rootScope", "tgDatePickerConfigService", DateSelectorDirective])
|
module.directive("tgDateSelector", ["$rootScope", "tgDatePickerConfigService", DateSelectorDirective])
|
||||||
|
|
|
@ -6,7 +6,7 @@ form
|
||||||
input.sprint-name(
|
input.sprint-name(
|
||||||
type="text"
|
type="text"
|
||||||
name="name"
|
name="name"
|
||||||
ng-model="sprint.name"
|
ng-model="newSprint.name"
|
||||||
ng-model-options="{ debounce: 200 }"
|
ng-model-options="{ debounce: 200 }"
|
||||||
data-required="true"
|
data-required="true"
|
||||||
data-maxlength="500"
|
data-maxlength="500"
|
||||||
|
@ -19,16 +19,16 @@ form
|
||||||
input.date-start(
|
input.date-start(
|
||||||
type="text"
|
type="text"
|
||||||
name="estimated_start"
|
name="estimated_start"
|
||||||
ng-model="sprint.estimated_start"
|
picker-value="{{newSprint.estimated_start}}"
|
||||||
data-required="true"
|
data-required="true"
|
||||||
tg-date-selector
|
tg-date-selector
|
||||||
placeholder="{{'LIGHTBOX.ADD_EDIT_SPRINT.PLACEHOLDER_SPRINT_START' | translate}}"
|
placeholder="{{'LIGHTBOX.ADD_EDIT_SPRINT.PLACEHOLDER_SPRINT_START' | translate}}"
|
||||||
)
|
)
|
||||||
div
|
div
|
||||||
input.date-end(
|
input.date-end(
|
||||||
type="text"
|
type="text"
|
||||||
name="estimated_finish"
|
name="estimated_finish"
|
||||||
ng-model="sprint.estimated_finish"
|
picker-value="{{newSprint.estimated_finish}}"
|
||||||
data-required="true"
|
data-required="true"
|
||||||
tg-date-selector
|
tg-date-selector
|
||||||
placeholder="{{'LIGHTBOX.ADD_EDIT_SPRINT.PLACEHOLDER_SPRINT_END' | translate}}"
|
placeholder="{{'LIGHTBOX.ADD_EDIT_SPRINT.PLACEHOLDER_SPRINT_END' | translate}}"
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
header(tg-backlog-sprint-header, ng-model="sprint")
|
header(tg-backlog-sprint-header)
|
||||||
|
|
||||||
.summary-progress-wrapper
|
.summary-progress-wrapper
|
||||||
div.sprint-progress-bar(tg-progress-bar="100 * sprint.closed_points / sprint.total_points")
|
div.sprint-progress-bar(tg-progress-bar="100 * sprint.closed_points / sprint.total_points")
|
||||||
|
|
|
@ -29,7 +29,7 @@ section.sprints
|
||||||
tg-check-permission="add_milestone"
|
tg-check-permission="add_milestone"
|
||||||
)
|
)
|
||||||
|
|
||||||
div.sprint.sprint-open(ng-repeat="sprint in openSprints track by sprint.id",
|
div.sprint.sprint-open(ng-repeat="sprint in ctrl.openSprints() track by sprint.id",
|
||||||
tg-backlog-sprint="sprint",
|
tg-backlog-sprint="sprint",
|
||||||
tg-sprint-sortable)
|
tg-sprint-sortable)
|
||||||
include sprint
|
include sprint
|
||||||
|
|
Loading…
Reference in New Issue