mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-19 13:54:25 +01:00
optimization collaborators of a project
This commit is contained in:
parent
90f77ca929
commit
a325211552
@ -24,7 +24,7 @@
|
||||
# - $state (Ui-Router) [ 'app.public.projects_show', 'app.public.projects_list' ]
|
||||
##
|
||||
class ProjectsController
|
||||
constructor: ($scope, $state, Project, Machine, Member, Component, Theme, Licence, $document)->
|
||||
constructor: ($scope, $state, Project, Machine, Member, Component, Theme, Licence, $document, Diacritics)->
|
||||
|
||||
## Retrieve the list of machines from the server
|
||||
Machine.query().$promise.then (data)->
|
||||
@ -140,6 +140,17 @@ class ProjectsController
|
||||
$scope.project.project_steps_attributes.splice(index, 1)
|
||||
|
||||
|
||||
$scope.autoCompleteName = (nameLookup) ->
|
||||
unless nameLookup
|
||||
return
|
||||
asciiName = Diacritics.remove(nameLookup)
|
||||
|
||||
Member.search { query: asciiName }, (users) ->
|
||||
$scope.matchingMembers = users
|
||||
, (error)->
|
||||
console.error(error)
|
||||
|
||||
|
||||
|
||||
##
|
||||
# Controller used on projects listing page
|
||||
@ -275,8 +286,8 @@ Application.Controllers.controller "ProjectsController", ["$scope", "$state", 'P
|
||||
##
|
||||
# Controller used in the project creation page
|
||||
##
|
||||
Application.Controllers.controller "NewProjectController", ["$scope", "$state", 'Project', 'Machine', 'Member', 'Component', 'Theme', 'Licence', '$document', 'CSRF'
|
||||
, ($scope, $state, Project, Machine, Member, Component, Theme, Licence, $document, CSRF) ->
|
||||
Application.Controllers.controller "NewProjectController", ["$scope", "$state", 'Project', 'Machine', 'Member', 'Component', 'Theme', 'Licence', '$document', 'CSRF', 'Diacritics'
|
||||
, ($scope, $state, Project, Machine, Member, Component, Theme, Licence, $document, CSRF, Diacritics) ->
|
||||
CSRF.setMetaTags()
|
||||
|
||||
## API URL where the form will be posted
|
||||
@ -290,16 +301,10 @@ Application.Controllers.controller "NewProjectController", ["$scope", "$state",
|
||||
project_steps_attributes: []
|
||||
project_caos_attributes: []
|
||||
|
||||
## Other members list (project collaborators)
|
||||
Member.query().$promise.then (data)->
|
||||
$scope.members = data.filter (m) ->
|
||||
m.id != $scope.currentUser.id
|
||||
.map (d) ->
|
||||
id: d.id
|
||||
name: d.name
|
||||
$scope.matchingMembers = []
|
||||
|
||||
## Using the ProjectsController
|
||||
new ProjectsController($scope, $state, Project, Machine, Member, Component, Theme, Licence, $document)
|
||||
new ProjectsController($scope, $state, Project, Machine, Member, Component, Theme, Licence, $document, Diacritics)
|
||||
]
|
||||
|
||||
|
||||
@ -307,8 +312,8 @@ Application.Controllers.controller "NewProjectController", ["$scope", "$state",
|
||||
##
|
||||
# Controller used in the project edition page
|
||||
##
|
||||
Application.Controllers.controller "EditProjectController", ["$scope", "$state", '$stateParams', 'Project', 'Machine', 'Member', 'Component', 'Theme', 'Licence', '$document', 'CSRF', 'projectPromise'
|
||||
, ($scope, $state, $stateParams, Project, Machine, Member, Component, Theme, Licence, $document, CSRF, projectPromise) ->
|
||||
Application.Controllers.controller "EditProjectController", ["$scope", "$state", '$stateParams', 'Project', 'Machine', 'Member', 'Component', 'Theme', 'Licence', '$document', 'CSRF', 'projectPromise', 'Diacritics'
|
||||
, ($scope, $state, $stateParams, Project, Machine, Member, Component, Theme, Licence, $document, CSRF, projectPromise, Diacritics) ->
|
||||
CSRF.setMetaTags()
|
||||
|
||||
## API URL where the form will be posted
|
||||
@ -320,16 +325,10 @@ Application.Controllers.controller "EditProjectController", ["$scope", "$state",
|
||||
## Retrieve the project's details, if an error occured, redirect the user to the projects list page
|
||||
$scope.project = projectPromise
|
||||
|
||||
## Other members list (project collaborators)
|
||||
Member.query().$promise.then (data)->
|
||||
$scope.members = data.filter (m) ->
|
||||
m.id != $scope.project.author_id
|
||||
.map (d) ->
|
||||
id: d.id
|
||||
name: d.name
|
||||
$scope.matchingMembers = []
|
||||
|
||||
## Using the ProjectsController
|
||||
new ProjectsController($scope, $state, Project, Machine, Member, Component, Theme, Licence, $document)
|
||||
## Using the ProjectsController
|
||||
new ProjectsController($scope, $state, Project, Machine, Member, Component, Theme, Licence, $document, Diacritics)
|
||||
]
|
||||
|
||||
|
||||
|
@ -171,7 +171,7 @@
|
||||
<span ng-bind="$item.name"></span>
|
||||
<input type="hidden" name="project[user_ids][]" value="{{$item.id}}" />
|
||||
</ui-select-match>
|
||||
<ui-select-choices repeat="m.id as m in (members | filter: $select.search)">
|
||||
<ui-select-choices repeat="m in matchingMembers" refresh="autoCompleteName($select.search)" refresh-delay="300">
|
||||
<span ng-bind-html="m.name | highlight: $select.search"></span>
|
||||
</ui-select-choices>
|
||||
</ui-select>
|
||||
|
@ -180,7 +180,6 @@ class API::MembersController < API::ApiController
|
||||
end
|
||||
|
||||
def search
|
||||
authorize User
|
||||
|
||||
if params[:subscription]
|
||||
subscription = (params[:subscription] === 'true')
|
||||
@ -191,10 +190,16 @@ class API::MembersController < API::ApiController
|
||||
.where("users.is_active = 'true' AND roles.name = 'member'")
|
||||
.where("lower(f_unaccent(profiles.first_name)) LIKE ('%' || lower(f_unaccent(:search)) || '%') OR lower(f_unaccent(profiles.last_name)) LIKE ('%' || lower(f_unaccent(:search)) || '%')", search: params[:query])
|
||||
|
||||
if params[:subscription] === 'true'
|
||||
@members = @members.where('subscriptions.id IS NOT NULL AND subscriptions.expired_at >= :now', now: Date.today.to_s)
|
||||
elsif params[:subscription] === 'false'
|
||||
@members = @members.where('subscriptions.id IS NULL OR subscriptions.expired_at < :now', now: Date.today.to_s)
|
||||
if current_user.is_member?
|
||||
# non-admin can only retrieve users with "public profiles"
|
||||
@members = @members.where("users.is_allow_contact = 'true'")
|
||||
else
|
||||
# only admins have the ability to filter by subscription
|
||||
if params[:subscription] === 'true'
|
||||
@members = @members.where('subscriptions.id IS NOT NULL AND subscriptions.expired_at >= :now', now: Date.today.to_s)
|
||||
elsif params[:subscription] === 'false'
|
||||
@members = @members.where('subscriptions.id IS NULL OR subscriptions.expired_at < :now', now: Date.today.to_s)
|
||||
end
|
||||
end
|
||||
|
||||
@members
|
||||
|
@ -4,7 +4,7 @@ class UserPolicy < ApplicationPolicy
|
||||
if user.is_admin?
|
||||
scope.includes(:group, :training_credits, :machine_credits, :subscriptions => [:plan => [:credits]], :profile => [:user_avatar]).joins(:roles).where("users.is_active = 'true' AND roles.name = 'member'").order('users.created_at desc')
|
||||
else
|
||||
scope.includes(:group, :training_credits, :machine_credits, :profile => [:user_avatar]).joins(:roles).where("users.is_active = 'true' AND roles.name = 'member'").where(is_allow_contact: true).order('users.created_at desc')
|
||||
scope.includes(:profile => [:user_avatar]).joins(:roles).where("users.is_active = 'true' AND roles.name = 'member'").where(is_allow_contact: true).order('users.created_at desc')
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -33,7 +33,4 @@ class UserPolicy < ApplicationPolicy
|
||||
user.is_admin?
|
||||
end
|
||||
|
||||
def search?
|
||||
user.is_admin?
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user