From 28c00233102f3462f9b1fa5900df1748a17eec9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa?= Date: Wed, 19 Sep 2018 10:10:55 +0200 Subject: [PATCH] Repair assign-to directives regressions --- .../assigned-to-inline.directive.coffee | 27 ++++++++++--------- .../assigned-users-inline.directive.coffee | 16 ++++------- 2 files changed, 20 insertions(+), 23 deletions(-) diff --git a/app/modules/components/assigned/assigned-to-inline.directive.coffee b/app/modules/components/assigned/assigned-to-inline.directive.coffee index f791d436..c2b611d3 100644 --- a/app/modules/components/assigned/assigned-to-inline.directive.coffee +++ b/app/modules/components/assigned/assigned-to-inline.directive.coffee @@ -18,14 +18,15 @@ ### AssignedToInlineDirective = ($rootscope, $confirm, $repo, $loading, $modelTransform, $template -$translate, $compile, $currentUserService, avatarService) -> - link = ($scope, $el, $attrs, $ctrl) -> +$translate, $compile, $currentUserService, avatarService, $userListService) -> + link = ($scope, $el, $attr, $model) -> isEditable = -> - return $scope.project?.my_permissions?.indexOf($attrs.requiredPerm) != -1 + return $scope.project?.my_permissions?.indexOf($attr.requiredPerm) != -1 renderUserList = (text) -> - activeUsers = _.reject($scope.activeUsers, {"id": $scope.selected.id}) if $scope.selected? - users = $ctrl.getUserList(activeUsersactiveUsers, $scope.user.id, text) + selectedId = $model.$modelValue.assigned_to + users = $userListService.searchUsers(text) + users = _.reject(users, {"id": selectedId}) if selectedId visibleUsers = _.slice(users, 0, 5) visibleUsers = _.map visibleUsers, (user) -> user.avatar = avatarService.getAvatar(user) @@ -58,16 +59,17 @@ $translate, $compile, $currentUserService, avatarService) -> $el.on "click", ".users-dropdown", (event) -> event.preventDefault() event.stopPropagation() + $scope.usersSearch = "" renderUserList() $scope.$apply() $el.find(".pop-users").popover().open() $scope.selfAssign = () -> - $attr.ngModel.assigned_to = $currentUserService.getUser().get('id') - renderUser($attr.ngModel) + $model.$modelValue.assigned_to = $currentUserService.getUser().get('id') + renderUser($model.$modelValue) $scope.unassign = () -> - $attr.ngModel.assigned_to = null + $model.$modelValue.assigned_to = null renderUser() $scope.$watch "usersSearch", (searchingText) -> @@ -78,11 +80,11 @@ $translate, $compile, $currentUserService, avatarService) -> $el.on "click", ".user-list-single", (event) -> event.preventDefault() target = angular.element(event.currentTarget) - $attr.ngModel.assigned_to = target.data("user-id") - renderUser($attr.ngModel) + $model.$modelValue.assigned_to = target.data("user-id") + renderUser($model.$modelValue) $scope.$apply() - $scope.$watch $attrs.ngModel, (instance) -> + $scope.$watch $attr.ngModel, (instance) -> renderUser(instance) $scope.$on "isiocaine:changed", (ctx, instance) -> @@ -94,8 +96,9 @@ $translate, $compile, $currentUserService, avatarService) -> return { link:link, templateUrl: "common/components/assigned-to-inline.html" + require:"ngModel" } angular.module('taigaComponents').directive("tgAssignedToInline", ["$rootScope", "$tgConfirm", "$tgRepo", "$tgLoading", "$tgQueueModelTransformation", "$tgTemplate", "$translate", "$compile", -"tgCurrentUserService", "tgAvatarService", AssignedToInlineDirective]) +"tgCurrentUserService", "tgAvatarService", "tgUserListService", AssignedToInlineDirective]) diff --git a/app/modules/components/assigned/assigned-users-inline.directive.coffee b/app/modules/components/assigned/assigned-users-inline.directive.coffee index 975cbef1..d4a42c10 100644 --- a/app/modules/components/assigned/assigned-users-inline.directive.coffee +++ b/app/modules/components/assigned/assigned-users-inline.directive.coffee @@ -73,6 +73,7 @@ $translate, $compile, $currentUserService, avatarService, $userListService) -> $el.on "click", ".users-dropdown", (event) -> event.preventDefault() event.stopPropagation() + $scope.usersSearch = "" renderUsersList() $scope.$apply() $el.find(".pop-users").popover().open() @@ -84,17 +85,10 @@ $translate, $compile, $currentUserService, avatarService, $userListService) -> $scope.usersSearch = null $scope.unassign = (user) -> - assignedUserId = user.id - - title = $translate.instant("COMMON.ASSIGNED_USERS.TITLE_LIGHTBOX_DELETE_ASSIGNED") - message = $scope.usersById[assignedUserId].full_name_display - - $confirm.askOnDelete(title, message).then (askResponse) -> - users = $model.$modelValue.assigned_users - users.splice(users.indexOf(assignedUserId), 1) - renderUsers() - applyToModel() - askResponse.finish() + userIndex = currentAssignedIds.indexOf(user.id) + currentAssignedIds.splice(userIndex, 1) + renderUsers() + applyToModel() $el.on "click", ".users-search", (event) -> event.stopPropagation()