Merge pull request #1138 from taigaio/issue/4417/crazy-dates

add an independent object in the sprint form and destroy datapicker e…
stable
Alejandro 2016-10-21 09:08:27 +02:00 committed by GitHub
commit 90e37b940b
8 changed files with 70 additions and 45 deletions

View File

@ -37,11 +37,12 @@ CreateEditSprint = ($repo, $confirm, $rs, $rootscope, lightboxService, $loading,
hasErrors = false
createSprint = true
form = null
$scope.newSprint = {}
resetSprint = () ->
form.reset() if form
$scope.sprint = {
$scope.newSprint = {
project: null
name: null
estimated_start: null
@ -62,19 +63,23 @@ CreateEditSprint = ($repo, $confirm, $rs, $rootscope, lightboxService, $loading,
return
hasErrors = false
newSprint = angular.copy($scope.sprint)
broadcastEvent = null
estimated_start = $('.date-start').val()
estimated_end = $('.date-end').val()
if createSprint
newSprint.estimated_start = moment(newSprint.estimated_start, prettyDate).format("YYYY-MM-DD")
newSprint.estimated_finish = moment(newSprint.estimated_finish,prettyDate).format("YYYY-MM-DD")
newSprint = angular.copy($scope.newSprint)
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)
broadcastEvent = "sprintform:create:success"
else
newSprint.setAttr("estimated_start",
moment(newSprint.estimated_start, prettyDate).format("YYYY-MM-DD"))
newSprint.setAttr("estimated_finish",
moment(newSprint.estimated_finish, prettyDate).format("YYYY-MM-DD"))
newSprint = $scope.newSprint.realClone()
newSprint.estimated_start = moment(estimated_start, prettyDate).format("YYYY-MM-DD")
newSprint.estimated_finish = moment(estimated_end, prettyDate).format("YYYY-MM-DD")
promise = $repo.save(newSprint)
broadcastEvent = "sprintform:edit:success"
@ -85,6 +90,13 @@ CreateEditSprint = ($repo, $confirm, $rs, $rootscope, lightboxService, $loading,
promise.then (data) ->
currentLoading.finish()
$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)
lightboxService.close($el)
@ -100,19 +112,19 @@ CreateEditSprint = ($repo, $confirm, $rs, $rootscope, lightboxService, $loading,
remove = ->
title = $translate.instant("LIGHTBOX.DELETE_SPRINT.TITLE")
message = $scope.sprint.name
message = $scope.newSprint.name
$confirm.askOnDelete(title, message).then (askResponse) =>
onSuccess = ->
askResponse.finish()
$scope.milestonesCounter -= 1
lightboxService.close($el)
$rootscope.$broadcast("sprintform:remove:success", $scope.sprint)
$rootscope.$broadcast("sprintform:remove:success", $scope.newSprint)
onError = ->
askResponse.finish(false)
$confirm.notify("error")
$repo.remove($scope.sprint).then(onSuccess, onError)
$repo.remove($scope.newSprint).then(onSuccess, onError)
getLastSprint = ->
openSprints = _.filter $scope.sprints, (sprint) ->
@ -131,9 +143,9 @@ CreateEditSprint = ($repo, $confirm, $rs, $rootscope, lightboxService, $loading,
createSprint = true
prettyDate = $translate.instant("COMMON.PICKERDATE.FORMAT")
$scope.sprint.project = projectId
$scope.sprint.name = null
$scope.sprint.slug = null
$scope.newSprint.project = projectId
$scope.newSprint.name = null
$scope.newSprint.slug = null
lastSprint = getLastSprint()
@ -141,19 +153,19 @@ CreateEditSprint = ($repo, $confirm, $rs, $rootscope, lightboxService, $loading,
if lastSprint
estimatedStart = moment(lastSprint.estimated_finish)
else if $scope.sprint.estimated_start
estimatedStart = moment($scope.sprint.estimated_start)
else if $scope.newSprint.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")
if lastSprint
estimatedFinish = moment(lastSprint.estimated_finish).add(2, "weeks")
else if $scope.sprint.estimated_finish
estimatedFinish = moment($scope.sprint.estimated_finish)
else if $scope.newSprint.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")
if lastSprint?.name?
@ -179,10 +191,10 @@ CreateEditSprint = ($repo, $confirm, $rs, $rootscope, lightboxService, $loading,
createSprint = false
prettyDate = $translate.instant("COMMON.PICKERDATE.FORMAT")
$scope.$apply ->
$scope.sprint = sprint
$scope.sprint.estimated_start = moment($scope.sprint.estimated_start).format(prettyDate)
$scope.sprint.estimated_finish = moment($scope.sprint.estimated_finish).format(prettyDate)
$scope.$apply () ->
$scope.newSprint = sprint.realClone()
$scope.newSprint.estimated_start = moment($scope.newSprint.estimated_start).format(prettyDate)
$scope.newSprint.estimated_finish = moment($scope.newSprint.estimated_finish).format(prettyDate)
$el.find(".delete-sprint").removeClass("hidden")

View File

@ -239,7 +239,7 @@ class BacklogController extends mixOf(taiga.Controller, taiga.PageMixin, taiga.F
sprint.user_stories = _.sortBy(sprint.user_stories, "sprint_order")
@scope.sprints = sprints
@scope.openSprints = _.filter(sprints, (sprint) => not sprint.closed).reverse()
@scope.closedSprints = [] if !@scope.closedSprints
@scope.sprintsCounter = sprints.length
@ -250,6 +250,9 @@ class BacklogController extends mixOf(taiga.Controller, taiga.PageMixin, taiga.F
return sprints
openSprints: ->
return _.filter(@scope.sprints, (sprint) => not sprint.closed).reverse()
loadAllPaginatedUserstories: () ->
page = @.page

View File

@ -98,6 +98,7 @@ BacklogSprintHeaderDirective = ($navUrls, $template, $compile, $translate) ->
start = moment(sprint.estimated_start).format(prettyDate)
finish = moment(sprint.estimated_finish).format(prettyDate)
estimatedDateRange = "#{start}-#{finish}"
ctx = {
@ -117,19 +118,15 @@ BacklogSprintHeaderDirective = ($navUrls, $template, $compile, $translate) ->
compiledTemplate = $compile(template)(templateScope)
$el.html(compiledTemplate)
$scope.$watch $attrs.ngModel, (sprint) ->
$scope.$watch "sprint", (sprint) ->
render(sprint)
$scope.$on "sprintform:edit:success", ->
render($model.$modelValue)
$scope.$on "$destroy", ->
$el.off()
return {
link: link
restrict: "EA"
require: "ngModel"
}
module.directive("tgBacklogSprintHeader", ["$tgNavUrls", "$tgTemplate", "$compile", "$translate"

View File

@ -31,6 +31,16 @@ class Model
@.setAttrs(data)
@.initialize()
realClone: ->
attrs = _.cloneDeep(@._attrs)
instance = new Model(@._name, attrs, @._dataTypes)
instance._modifiedAttrs = _.cloneDeep(@._modifiedAttrs)
instance._isModified = _.cloneDeep(@._isModified)
return instance
clone: ->
instance = new Model(@._name, @._attrs, @._dataTypes)
instance._modifiedAttrs = @._modifiedAttrs

View File

@ -64,27 +64,30 @@ DateSelectorDirective = ($rootscope, datePickerConfigService) ->
_.merge(datePickerConfig, {
field: $el[0]
onSelect: (date) =>
selectedDate = date
onOpen: =>
$el.picker.setDate(selectedDate) if selectedDate?
})
$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) ->
initialize() if val? and not $el.picker
$el.picker.setDate(val) if val?
$attrs.$observe "pickerValue", (val) ->
$el.val(val)
if val?
$el.picker.destroy() if $el.picker
initialize()
$el.picker.setDate(val)
$scope.$on "$destroy", ->
$el.off()
unbind()
$el.picker.destroy()
return {
link: link
require: "ngModel"
}
module.directive("tgDateSelector", ["$rootScope", "tgDatePickerConfigService", DateSelectorDirective])

View File

@ -6,7 +6,7 @@ form
input.sprint-name(
type="text"
name="name"
ng-model="sprint.name"
ng-model="newSprint.name"
ng-model-options="{ debounce: 200 }"
data-required="true"
data-maxlength="500"
@ -19,16 +19,16 @@ form
input.date-start(
type="text"
name="estimated_start"
ng-model="sprint.estimated_start"
picker-value="{{newSprint.estimated_start}}"
data-required="true"
tg-date-selector
tg-date-selector
placeholder="{{'LIGHTBOX.ADD_EDIT_SPRINT.PLACEHOLDER_SPRINT_START' | translate}}"
)
div
input.date-end(
type="text"
name="estimated_finish"
ng-model="sprint.estimated_finish"
picker-value="{{newSprint.estimated_finish}}"
data-required="true"
tg-date-selector
placeholder="{{'LIGHTBOX.ADD_EDIT_SPRINT.PLACEHOLDER_SPRINT_END' | translate}}"

View File

@ -1,4 +1,4 @@
header(tg-backlog-sprint-header, ng-model="sprint")
header(tg-backlog-sprint-header)
.summary-progress-wrapper
div.sprint-progress-bar(tg-progress-bar="100 * sprint.closed_points / sprint.total_points")

View File

@ -29,7 +29,7 @@ section.sprints
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-sprint-sortable)
include sprint