Allowing leave project

stable
Alejandro Alonso 2014-11-26 15:49:45 +01:00 committed by Jesús Espino
parent 2a4680b529
commit b725b6c6e1
3 changed files with 31 additions and 12 deletions

View File

@ -22,7 +22,7 @@
taiga = @.taiga taiga = @.taiga
resourceProvider = ($repo) -> resourceProvider = ($repo, $http, $urls) ->
service = {} service = {}
service.get = (id) -> service.get = (id) ->
@ -46,7 +46,8 @@ resourceProvider = ($repo) ->
return $repo.queryOneRaw("projects", "#{projectId}/stats") return $repo.queryOneRaw("projects", "#{projectId}/stats")
service.leave = (projectId) -> service.leave = (projectId) ->
return $repo.queryOneRaw("projects", "#{projectId}/leave") url = "#{$urls.resolve("projects")}/#{projectId}/leave"
return $http.post(url)
service.memberStats = (projectId) -> service.memberStats = (projectId) ->
return $repo.queryOneRaw("projects", "#{projectId}/member_stats") return $repo.queryOneRaw("projects", "#{projectId}/member_stats")
@ -59,4 +60,4 @@ resourceProvider = ($repo) ->
module = angular.module("taigaResources") module = angular.module("taigaResources")
module.factory("$tgProjectsResourcesProvider", ["$tgRepo", resourceProvider]) module.factory("$tgProjectsResourcesProvider", ["$tgRepo", "$tgHttp", "$tgUrls", resourceProvider])

View File

@ -32,6 +32,7 @@ module = angular.module("taigaTeam")
class TeamController extends mixOf(taiga.Controller, taiga.PageMixin) class TeamController extends mixOf(taiga.Controller, taiga.PageMixin)
@.$inject = [ @.$inject = [
"$scope", "$scope",
"$rootScope",
"$tgRepo", "$tgRepo",
"$tgResources", "$tgResources",
"$routeParams", "$routeParams",
@ -41,7 +42,7 @@ class TeamController extends mixOf(taiga.Controller, taiga.PageMixin)
"tgLoader" "tgLoader"
] ]
constructor: (@scope, @repo, @rs, @params, @q, @appTitle, @auth, tgLoader) -> constructor: (@scope, @rootscope, @repo, @rs, @params, @q, @appTitle, @auth, tgLoader) ->
@scope.sectionName = "Team" @scope.sectionName = "Team"
promise = @.loadInitialData() promise = @.loadInitialData()
@ -55,6 +56,12 @@ class TeamController extends mixOf(taiga.Controller, taiga.PageMixin)
# On Error # On Error
promise.then null, @.onInitialDataError.bind(@) promise.then null, @.onInitialDataError.bind(@)
<<<<<<< HEAD
=======
@scope.currentUser = @auth.getUser()
@scope.projectId = @rootscope.projectId
>>>>>>> Allowing leave project
setRole: (role) -> setRole: (role) ->
if role if role
@scope.filtersRole = role @scope.filtersRole = role
@ -190,7 +197,7 @@ TeamMemberCurrentUserDirective = () ->
<figcaption> <figcaption>
<span class="name" tg-bo-bind="currentUser.full_name"></span> <span class="name" tg-bo-bind="currentUser.full_name"></span>
<span class="position" tg-bo-bind="currentUser.role_name"></span> <span class="position" tg-bo-bind="currentUser.role_name"></span>
<div tg-leave-project></div> <div tg-leave-project projectid="{{projectId}}"></div>
</figcaption> </figcaption>
</figure> </figure>
</div> </div>
@ -200,6 +207,7 @@ TeamMemberCurrentUserDirective = () ->
return { return {
template: template template: template
scope: { scope: {
projectId: "=projectid",
currentUser: "=currentuser", currentUser: "=currentuser",
stats: "=" stats: "="
} }
@ -242,22 +250,32 @@ module.directive("tgTeamMembers", TeamMembersDirective)
## Leave project Directive ## Leave project Directive
############################################################################# #############################################################################
LeaveProjectDirective = ($repo, $confirm, $location) -> LeaveProjectDirective = ($repo, $confirm, $location, $rs, $navurls) ->
template= """ template= """
<a ng-click="leave()" href="" class="leave-project"> <a ng-click="leave()" href="" class="leave-project">
<span class="icon icon-delete"></span>Leave this project <span class="icon icon-delete"></span>Leave this project
</a> </a>
""" #TODO: i18n """ #TODO: i18n
link = ($scope) -> link = ($scope, $el, $attrs) ->
$scope.leave = () -> $scope.leave = () ->
$confirm.ask("Leave this project", "Are you sure you want to leave the project?")#TODO: i18n #TODO: i18n
.then (finish) => $confirm.ask("Leave this project", "Are you sure you want to leave the project?").then (finish) =>
console.log "TODO" promise = $rs.projects.leave($attrs.projectid)
promise.then =>
finish()
$confirm.notify("success")
$location.path($navurls.resolve("home"))
promise.then null, (response) ->
finish()
$confirm.notify('error', response.data._error_message)
return { return {
scope: {}, scope: {},
template: template, template: template,
link: link link: link
} }
module.directive("tgLeaveProject", ["$tgRepo", "$tgConfirm", "$tgLocation", LeaveProjectDirective]) module.directive("tgLeaveProject", ["$tgRepo", "$tgConfirm", "$tgLocation", "$tgResources", "$tgNavUrls", LeaveProjectDirective])

View File

@ -26,7 +26,7 @@ section.table-team.basic-table
div.popover.attribute-explanation div.popover.attribute-explanation
span How far did you go into this Taiga? span How far did you go into this Taiga?
div.hero(tg-team-current-user, stats="stats", currentuser="currentUser") div.hero(tg-team-current-user, stats="stats", currentuser="currentUser", projectid="projectId")
h2 h2
span Team > span Team >