Fix create due dates

stable
Álex Hermida 2018-08-07 14:40:55 +02:00 committed by Alex Hermida
parent 156f313e04
commit 4409cfbbfc
2 changed files with 82 additions and 17 deletions

View File

@ -33,7 +33,6 @@ bindOnce = @.taiga.bindOnce
debounce = @.taiga.debounce debounce = @.taiga.debounce
getDefaulColorList = @.taiga.getDefaulColorList getDefaulColorList = @.taiga.getDefaulColorList
module = angular.module("taigaAdmin") module = angular.module("taigaAdmin")
############################################################################# #############################################################################
@ -270,9 +269,8 @@ ProjectValuesDirective = ($log, $repo, $confirm, $location, animationFrame, $tra
$scope.newValue.order = if $scope.maxValueOrder then $scope.maxValueOrder + 1 else 1 $scope.newValue.order = if $scope.maxValueOrder then $scope.maxValueOrder + 1 else 1
promise = $repo.create(valueType, $scope.newValue) promise = $repo.create(valueType, $scope.newValue)
promise.then (data) => promise.then (data) ->
target.addClass("hidden") target.addClass("hidden")
$scope.values.push(data) $scope.values.push(data)
$scope.maxValueOrder = data.order $scope.maxValueOrder = data.order
initializeNewValue() initializeNewValue()
@ -329,11 +327,6 @@ ProjectValuesDirective = ($log, $repo, $confirm, $location, animationFrame, $tra
target = angular.element(event.currentTarget) target = angular.element(event.currentTarget)
saveValue(target) saveValue(target)
$el.on "click", ".save", (event) ->
event.preventDefault()
target = angular.element(event.currentTarget)
saveValue(target)
$el.on "click", ".cancel", (event) -> $el.on "click", ".cancel", (event) ->
event.preventDefault() event.preventDefault()
target = angular.element(event.currentTarget) target = angular.element(event.currentTarget)
@ -387,6 +380,17 @@ ProjectDueDatesValues = ($log, $repo, $confirm, $location, animationFrame, $tran
$translate, $rootscope, projectService) $translate, $rootscope, projectService)
linkDueDateStatusValue = ($scope, $el, $attrs) -> linkDueDateStatusValue = ($scope, $el, $attrs) ->
valueType = $attrs.type
initializeNewValue = ->
$scope.newValue = {
"name": ""
"days_to_due": 0
"sign": 1
}
initializeNewValue()
_setDaysToDue = (value) -> _setDaysToDue = (value) ->
value.days_to_due = value.days_to_due_abs * value.sign value.days_to_due = value.days_to_due_abs * value.sign
@ -394,8 +398,32 @@ ProjectDueDatesValues = ($log, $repo, $confirm, $location, animationFrame, $tran
target = angular.element(event.currentTarget) target = angular.element(event.currentTarget)
row = target.parents(".row.table-main") row = target.parents(".row.table-main")
formEl = target.parents("form") formEl = target.parents("form")
if not formEl.scope().value
return formEl.scope().newValue
else
return formEl.scope().value return formEl.scope().value
saveNewValue = (target) ->
formEl = target.parents("form")
form = formEl.checksley()
return if not form.validate()
$scope.newValue.project = $scope.project.id
$scope.newValue.order = if $scope.maxValueOrder then $scope.maxValueOrder + 1 else 1
promise = $repo.create(valueType, $scope.newValue)
promise.then (data) ->
target.addClass("hidden")
data.days_to_due_abs = data.days_to_due
data.sign = 1
$scope.values.push(data)
initializeNewValue()
promise.then null, (data) ->
form.setErrors(data)
$el.on "input", ".days-to-due-abs", (event) -> $el.on "input", ".days-to-due-abs", (event) ->
event.preventDefault() event.preventDefault()
value = _valueFromEventTarget(event) value = _valueFromEventTarget(event)
@ -409,6 +437,11 @@ ProjectDueDatesValues = ($log, $repo, $confirm, $location, animationFrame, $tran
value.sign = value.sign * -1 value.sign = value.sign * -1
_setDaysToDue(value) _setDaysToDue(value)
$el.on "click", ".add-new-due-date", debounce 2000, (event) ->
event.preventDefault()
target = $el.find(".new-value")
saveNewValue(target)
return { return {
link: ($scope, $el, $attrs) -> link: ($scope, $el, $attrs) ->
parentDirective.link($scope, $el, $attrs) parentDirective.link($scope, $el, $attrs)

View File

@ -25,10 +25,10 @@ section.colors-table.admin-status-table
span {{ value.name }} span {{ value.name }}
div.thresold-column div.thresold-column
span(ng-if="value.days_to_due_abs != null") {{ value.days_to_due_abs }} span(ng-if="value.days_to_due != null") {{ value.days_to_due_abs }}
div.before-after-column div.before-after-column
span(ng-if="value.days_to_due_abs", ng-switch="value.days_to_due >= 0") span(ng-if="value.days_to_due", ng-switch="value.days_to_due >= 0")
span(ng-switch-when="true") {{ 'ADMIN.PROJECT_DUE_DATE_STATUS.BEFORE' | translate }} span(ng-switch-when="true") {{ 'ADMIN.PROJECT_DUE_DATE_STATUS.BEFORE' | translate }}
span(ng-switch-when="false") {{ 'ADMIN.PROJECT_DUE_DATE_STATUS.AFTER' | translate }} span(ng-switch-when="false") {{ 'ADMIN.PROJECT_DUE_DATE_STATUS.AFTER' | translate }}
@ -63,7 +63,12 @@ section.colors-table.admin-status-table
) )
div.thresold-column(ng-if="!value.by_default") div.thresold-column(ng-if="!value.by_default")
input.days-to-due-abs(type="number", min="0", name="days_to_due_abs", ng-model="value.days_to_due_abs") input.days-to-due-abs(
type="number"
data-type="digits"
min="0"
name="days_to_due"
ng-model="value.days_to_due_abs")
div.before-after-column div.before-after-column
div.before-after-selector(ng-if="!value.by_default && value.days_to_due_abs != 0") div.before-after-selector(ng-if="!value.by_default && value.days_to_due_abs != 0")
@ -97,7 +102,7 @@ section.colors-table.admin-status-table
a.cancel(href="", title="{{'COMMON.CANCEL' | translate}}") a.cancel(href="", title="{{'COMMON.CANCEL' | translate}}")
tg-svg.cancel(svg-icon="icon-close") tg-svg.cancel(svg-icon="icon-close")
form form(tg-bind-scope)
div.row.table-main.new-value.hidden div.row.table-main.new-value.hidden
div.color-column( div.color-column(
tg-color-selection tg-color-selection
@ -117,16 +122,43 @@ section.colors-table.admin-status-table
) )
div.thresold-column div.thresold-column
input( input.days-to-due-abs(
name="days_to_due"
type="number" type="number"
data-type="digits"
min="0"
name="days_to_due_abs"
placeholder="{{'ADMIN.STATUS.PLACEHOLDER_DAYS_TO_DUE_DATE' | translate}}" placeholder="{{'ADMIN.STATUS.PLACEHOLDER_DAYS_TO_DUE_DATE' | translate}}"
ng-model="newValue.days_to_due" ng-model="newValue.days_to_due_abs"
data-required="true" data-required="true"
) )
div.before-after-column
div.before-after-selector(ng-if="newValue.days_to_due_abs && newValue.days_to_due_abs != 0")
.before-after-selector-single(ng-class="{'checked': newValue.sign > 0 }")
input(
type='radio'
id="due-date-status-before"
name="due-date-status-after"
ng-model="newValue.sign"
value="1"
)
label.days-to-due-sign(
for="due-date-status-before",
) {{ 'ADMIN.PROJECT_DUE_DATE_STATUS.BEFORE' | translate }}
.before-after-selector-single(ng-class="{'checked': newValue.sign < 0}")
input(
type='radio'
id="due-date-status-after"
name="due-date-status-after"
ng-model="newValue.sign"
value="-1"
)
label.days-to-due-sign(
for="due-date-status-after",
) {{ 'ADMIN.PROJECT_DUE_DATE_STATUS.AFTER' | translate }}
div.options-column div.options-column
a.add-new.e2e-save(href="", title="{{'COMMON.ADD' | translate}}") a.add-new-due-date.e2e-save(href="", title="{{'COMMON.ADD' | translate}}")
tg-svg(svg-icon="icon-save") tg-svg(svg-icon="icon-save")
a.delete-new(href="", title="{{'COMMON.CANCEL' | translate}}") a.delete-new(href="", title="{{'COMMON.CANCEL' | translate}}")