Improve history controller for more convenient way to load resources.
parent
86bd242ee6
commit
3fa4365a3d
|
@ -34,12 +34,15 @@ class HistoryController extends taiga.Controller
|
||||||
|
|
||||||
constructor: (@scope, @repo) ->
|
constructor: (@scope, @repo) ->
|
||||||
|
|
||||||
# TODO: possible move to resources
|
initialize: (type, objectId) ->
|
||||||
|
@.type = type
|
||||||
|
@.objectId = objectId
|
||||||
|
|
||||||
getHistory: (type, objectId) ->
|
getHistory: (type, objectId) ->
|
||||||
return @repo.queryOneRaw("history/#{type}", objectId)
|
return @repo.queryOneRaw("history/#{type}", objectId)
|
||||||
|
|
||||||
loadHistory: (type, objectId) ->
|
loadHistory: ->
|
||||||
return @.getHistory(type, objectId).then (history) =>
|
return @.getHistory(@.type, @.objectId).then (history) =>
|
||||||
for historyResult in history
|
for historyResult in history
|
||||||
# If description was modified take only the description_html field
|
# If description was modified take only the description_html field
|
||||||
if historyResult.values_diff.description?
|
if historyResult.values_diff.description?
|
||||||
|
@ -200,7 +203,9 @@ HistoryDirective = ($log) ->
|
||||||
bindOnce $scope, $attrs.ngModel, (model) ->
|
bindOnce $scope, $attrs.ngModel, (model) ->
|
||||||
type = $attrs.type
|
type = $attrs.type
|
||||||
objectId = model.id
|
objectId = model.id
|
||||||
$ctrl.loadHistory(type, objectId)
|
|
||||||
|
$ctrl.initialize(type, objectId)
|
||||||
|
$ctrl.loadHistory()
|
||||||
|
|
||||||
# Helpers
|
# Helpers
|
||||||
|
|
||||||
|
@ -325,9 +330,7 @@ HistoryDirective = ($log) ->
|
||||||
$scope.$watch("comments", renderComments)
|
$scope.$watch("comments", renderComments)
|
||||||
$scope.$watch("history", renderActivity)
|
$scope.$watch("history", renderActivity)
|
||||||
|
|
||||||
$scope.$on "history:reload", ->
|
$scope.$on("history:reload", -> $ctrl.loadHistory())
|
||||||
renderComments()
|
|
||||||
renderActivity()
|
|
||||||
|
|
||||||
# Events
|
# Events
|
||||||
|
|
||||||
|
@ -336,7 +339,7 @@ HistoryDirective = ($log) ->
|
||||||
|
|
||||||
$el.find(".comment-list").addClass("activeanimation")
|
$el.find(".comment-list").addClass("activeanimation")
|
||||||
onSuccess = ->
|
onSuccess = ->
|
||||||
$ctrl.loadHistory(type, objectId)
|
$ctrl.loadHistory()
|
||||||
|
|
||||||
onError = ->
|
onError = ->
|
||||||
$confirm.notify("error")
|
$confirm.notify("error")
|
||||||
|
|
Loading…
Reference in New Issue