Refactor tg-us-status directive: Create directive tg-created-by-display
parent
fff087a2ff
commit
d3fbfce06d
|
@ -46,6 +46,33 @@ DateRangeDirective = ->
|
||||||
module.directive("tgDateRange", DateRangeDirective)
|
module.directive("tgDateRange", DateRangeDirective)
|
||||||
|
|
||||||
|
|
||||||
|
#############################################################################
|
||||||
|
## Date Selector Directive (using pikaday)
|
||||||
|
#############################################################################
|
||||||
|
|
||||||
|
DateSelectorDirective =->
|
||||||
|
link = ($scope, $el, $attrs, $model) ->
|
||||||
|
selectedDate = null
|
||||||
|
$el.picker = new Pikaday({
|
||||||
|
field: $el[0]
|
||||||
|
format: "DD MMM YYYY"
|
||||||
|
onSelect: (date) =>
|
||||||
|
selectedDate = date
|
||||||
|
onOpen: =>
|
||||||
|
$el.picker.setDate(selectedDate) if selectedDate?
|
||||||
|
})
|
||||||
|
|
||||||
|
$scope.$watch $attrs.ngModel, (val) ->
|
||||||
|
$el.picker.setDate(val) if val?
|
||||||
|
|
||||||
|
return {
|
||||||
|
link: link
|
||||||
|
require: "ngModel"
|
||||||
|
}
|
||||||
|
|
||||||
|
module.directive("tgDateSelector", DateSelectorDirective)
|
||||||
|
|
||||||
|
|
||||||
#############################################################################
|
#############################################################################
|
||||||
## Sprint Progress Bar Directive
|
## Sprint Progress Bar Directive
|
||||||
#############################################################################
|
#############################################################################
|
||||||
|
@ -76,30 +103,48 @@ module.directive("tgSprintProgressbar", SprintProgressBarDirective)
|
||||||
|
|
||||||
|
|
||||||
#############################################################################
|
#############################################################################
|
||||||
## Date Selector Directive (using pikaday)
|
## Created-by display directive
|
||||||
#############################################################################
|
#############################################################################
|
||||||
|
|
||||||
DateSelectorDirective =->
|
CreatedByDisplayDirective = ->
|
||||||
link = ($scope, $el, $attrs, $model) ->
|
# Display the owner information (full name and photo) and the date of
|
||||||
selectedDate = null
|
# creation of an object (like USs, tasks and issues).
|
||||||
$el.picker = new Pikaday({
|
#
|
||||||
field: $el[0]
|
# Example:
|
||||||
format: "DD MMM YYYY"
|
# div.us-created-by(tg-created-by-display, ng-model="us")
|
||||||
onSelect: (date) =>
|
#
|
||||||
selectedDate = date
|
# Requirements:
|
||||||
onOpen: =>
|
# - model object must have the attributes 'created_date' and 'owner'
|
||||||
$el.picker.setDate(selectedDate) if selectedDate?
|
# - scope.usersById object is required.
|
||||||
})
|
|
||||||
|
|
||||||
$scope.$watch $attrs.ngModel, (val) ->
|
template = _.template("""
|
||||||
$el.picker.setDate(val) if val?
|
<div class="user-avatar">
|
||||||
|
<img src="<%= owner.photo %>" alt="<%- owner.full_name_display %>" />
|
||||||
|
</div>
|
||||||
|
|
||||||
return {
|
<div class="created-by">
|
||||||
link: link
|
<span class="created-title">Created by <%- owner.full_name_display %></span>
|
||||||
require: "ngModel"
|
<span class="created-date"><%- date %></span>
|
||||||
}
|
</div>
|
||||||
|
""") # TODO: i18n
|
||||||
|
|
||||||
module.directive("tgDateSelector", DateSelectorDirective)
|
link = ($scope, $el, $attrs) ->
|
||||||
|
render = (model) ->
|
||||||
|
html = template({
|
||||||
|
owner: $scope.usersById?[model.owner]
|
||||||
|
date: moment(model.created_date).format("DD MMM YYYY HH:mm")
|
||||||
|
})
|
||||||
|
$el.html(html)
|
||||||
|
|
||||||
|
bindOnce $scope, $attrs.ngModel, (model) ->
|
||||||
|
render(model) if model?
|
||||||
|
|
||||||
|
$scope.$on "$destroy", ->
|
||||||
|
$el.off()
|
||||||
|
|
||||||
|
return {link:link, require:"ngModel"}
|
||||||
|
|
||||||
|
module.directive("tgCreatedByDisplay", CreatedByDisplayDirective)
|
||||||
|
|
||||||
|
|
||||||
#############################################################################
|
#############################################################################
|
||||||
|
@ -194,6 +239,9 @@ WatchersDirective = ($rootscope, $confirm, $tgrepo) ->
|
||||||
$model.$setViewValue(item)
|
$model.$setViewValue(item)
|
||||||
save(item)
|
save(item)
|
||||||
|
|
||||||
|
$scope.$on "$destroy", ->
|
||||||
|
$el.off()
|
||||||
|
|
||||||
return {link:link, require:"ngModel"}
|
return {link:link, require:"ngModel"}
|
||||||
|
|
||||||
module.directive("tgWatchers", ["$rootScope", "$tgConfirm", "$tgRepo", WatchersDirective])
|
module.directive("tgWatchers", ["$rootScope", "$tgConfirm", "$tgRepo", WatchersDirective])
|
||||||
|
@ -272,6 +320,9 @@ AssignedToDirective = ($rootscope, $confirm, $tgrepo) ->
|
||||||
$model.$modelValue.assigned_to = userId
|
$model.$modelValue.assigned_to = userId
|
||||||
save($model.$modelValue)
|
save($model.$modelValue)
|
||||||
|
|
||||||
|
$scope.$on "$destroy", ->
|
||||||
|
$el.off()
|
||||||
|
|
||||||
return {
|
return {
|
||||||
link:link,
|
link:link,
|
||||||
require:"ngModel"
|
require:"ngModel"
|
||||||
|
@ -307,15 +358,15 @@ BlockButtonDirective = ($rootscope) ->
|
||||||
render(item)
|
render(item)
|
||||||
refresh(item)
|
refresh(item)
|
||||||
|
|
||||||
$scope.$on "$destroy", ->
|
|
||||||
$el.off()
|
|
||||||
|
|
||||||
$el.on "click", ".item-block", (event) ->
|
$el.on "click", ".item-block", (event) ->
|
||||||
$rootscope.$broadcast("block", $model.$modelValue)
|
$rootscope.$broadcast("block", $model.$modelValue)
|
||||||
|
|
||||||
$el.on "click", ".item-unblock", (event) ->
|
$el.on "click", ".item-unblock", (event) ->
|
||||||
$rootscope.$broadcast("unblock", $model.$modelValue)
|
$rootscope.$broadcast("unblock", $model.$modelValue)
|
||||||
|
|
||||||
|
$scope.$on "$destroy", ->
|
||||||
|
$el.off()
|
||||||
|
|
||||||
return {
|
return {
|
||||||
link: link
|
link: link
|
||||||
restrict: "EA"
|
restrict: "EA"
|
||||||
|
|
|
@ -53,9 +53,9 @@ block content
|
||||||
section.us-status
|
section.us-status
|
||||||
h1(tg-us-status-display, ng-model="us")
|
h1(tg-us-status-display, ng-model="us")
|
||||||
div.us-detail-progress-bar(tg-us-tasks-progress-display, ng-model="tasks")
|
div.us-detail-progress-bar(tg-us-tasks-progress-display, ng-model="tasks")
|
||||||
|
div.us-created-by(tg-created-by-display, ng-model="us")
|
||||||
|
|
||||||
section.us-assigned-to(tg-assigned-to, ng-model="us")
|
section.us-assigned-to(tg-assigned-to, ng-model="us")
|
||||||
section.us-created-by(tg-created-by, ng-model="us")
|
|
||||||
|
|
||||||
section.watchers(tg-watchers, ng-model="us")
|
section.watchers(tg-watchers, ng-model="us")
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue