Skip to content
This repository has been archived by the owner on Sep 7, 2023. It is now read-only.

Commit

Permalink
[#45] created staff people layout
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Stoica committed Apr 20, 2014
1 parent 2b289f4 commit 441e85e
Show file tree
Hide file tree
Showing 13 changed files with 229 additions and 97 deletions.
47 changes: 0 additions & 47 deletions app/assets/javascripts/controllers/adminUserCtrl.js

This file was deleted.

72 changes: 72 additions & 0 deletions app/assets/javascripts/controllers/userFilterCtrl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
"use strict";


/* this is reusable for the admin and staff user filtering */

angular.module("wrektranet.userFilterCtrl", [])

.controller('userFilterCtrl', [
'$scope',
'Restangular',
'promiseTracker',
function($scope, Restangular, promiseTracker) {
// fixes weird history bug in chrome. clicking a user and going back
// makes a json request instead of html
Restangular.setRequestSuffix('?1');

$scope.users = [];
$scope.loadingTracker = promiseTracker();
$scope.search = {};

// pagination
$scope.currentPage = 1;
$scope.maxSize = 11;
$scope.itemsPerPage = 20;

$scope.category = null;
$scope.status = 'active';

$scope.filterByRole = function(row) {
if ($scope.roleName) {
return !!_.where(row.roles, { name: $scope.roleName }).length;
} else {
return true;
}
}

$scope.concatenateRoles = function(roles) {
return _.pluck(roles, 'full_name').join(', ')
}

$scope.init = function(baseUrl, itemsPerPage) {
Restangular.setBaseUrl('/' + baseUrl);

if (itemsPerPage) {
$scope.itemsPerPage = itemsPerPage;
}

var promise = Restangular.one('users').getList()
.then(function(users) {
$scope.users = users;
});

$scope.$watch('category', function(newValue, oldValue) {
if ($scope.search) {
delete $scope.search.exec_staff;
delete $scope.search.admin;

switch (newValue) {
case 'admin':
$scope.search.admin = "true";
break;
case 'exec_staff':
$scope.search.exec_staff = "true";
break;
}
}
});

$scope.loadingTracker.addPromise(promise);
}
}
]);
2 changes: 1 addition & 1 deletion app/assets/javascripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ angular.module("wrektranet.controllers", [
"wrektranet.airProgramLogCtrl",
"wrektranet.adminProgramLogCtrl",
"wrektranet.listenerLogsCtrl",
"wrektranet.adminUserCtrl"
"wrektranet.userFilterCtrl"
]);

angular.module("wrektranet.filters", [
Expand Down
2 changes: 1 addition & 1 deletion app/assets/stylesheets/application.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ body {
white-space: nowrap;
}

.pagination, .pager {
.pagination, .pager a {
cursor: pointer;
}
6 changes: 3 additions & 3 deletions app/controllers/registrations_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class RegistrationsController < Devise::RegistrationsController
def update
@user = User.find(current_user.id)
if @user.update_attributes(account_update_params) and @user.sync_to_legacy_profile! and @user.sync_to_ldap
if @user.update_with_password(account_update_params) and @user.sync_to_legacy_profile! and @user.sync_to_ldap
set_flash_message :notice, :updated
# Sign in the user bypassing validation in case his password changed
sign_in @user, bypass: true
Expand All @@ -16,8 +16,8 @@ def account_update_params
permitted = [
:email, :subscribed_to_announce, :subscribed_to_staff,
:first_name, :middle_name, :last_name, :display_name,
:password, :password_confirmation, :phone,
:birthday_string, :avatar, :delete_avatar,
:current_password, :password, :password_confirmation, :phone,
:birthday_string, :avatar, :delete_avatar, :user_id,
legacy_profile_attributes: [:buzzcard_id, :buzzcard_fc]
]

Expand Down
4 changes: 4 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ def username_with_name
username + " - " + name
end

def name_with_username
name + " - " + username
end

def admin?
self.admin
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/staff_tickets/index.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ div ng-controller="adminTicketListCtrl"
form.form-inline.ng-cloak ng-submit="addTicket()" ng-hide="isContestFull()"
.form-group>
select.select.form-control ng-model="user_id" required="required"
option value="" Select another user
option value="" Award another user...
= options_from_collection_for_select (User.all - @contest.users), :id, :username_with_name, { prompt: 'Add a user' }
button.btn.btn-primary type="submit"
i.glyphicon.glyphicon-plus>
Expand Down
47 changes: 21 additions & 26 deletions app/views/admin/users/index.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -3,52 +3,50 @@
.page-header
h1 Users

div ng-controller="adminUserCtrl"
div ng-controller="userFilterCtrl" ng-init="init('admin')"
/ filter
form.form-horizontal
.row
.col-sm-4
.form-group
label.control-label.col-sm-3 Username
.col-sm-9
label.control-label.col-sm-4 Username
.col-sm-8
input.form-control type="text" ng-model="search.username"
.form-group
label.control-label.col-sm-3 Name
.col-sm-9
label.control-label.col-sm-4 Name
.col-sm-8
input.form-control type="text" ng-model="search.name"
.form-group
label.control-label.col-sm-3 Roles
.col-sm-9
/ I don't feel like implementing an inner-array search
/ this is being implemented as a full model search
select.form-control ng-model="search.$"
option value="" Any
label.control-label.col-sm-4 Role
.col-sm-8
select.form-control ng-model="roleName"
option value=""
- for role in @roles
option value="#{role.name}" = role.full_name
.col-sm-8
.form-group
label.control-label.col-sm-2 Category
.col-sm-10
.btn-group
button.btn.btn-default.btn-sm type="button" ng-model="category" btn-radio="null" All
button.btn.btn-default.btn-sm type="button" ng-model="category" btn-radio="'exec_staff'" Exec Staff
button.btn.btn-default.btn-sm type="button" ng-model="category" btn-radio="'admin'" Admins
button.btn.btn-sm.btn-default type="button" ng-model="category" btn-radio="null" All
button.btn.btn-sm.btn-default type="button" ng-model="category" btn-radio="'exec_staff'" Exec Staff
button.btn.btn-sm.btn-default type="button" ng-model="category" btn-radio="'admin'" Admins
.form-group
label.control-label.col-sm-2 Status
.col-sm-10
.btn-group
button.btn.btn-default.btn-sm type="button" ng-model="status" btn-radio="null" All
button.btn.btn-success.btn-sm type="button" ng-model="status" btn-radio="'active'" Active
button.btn.btn-info.btn-sm type="button" ng-model="status" btn-radio="'potential'" Potential
button.btn.btn-warning.btn-sm type="button" ng-model="status" btn-radio="'inactive'" Inactive
button.btn.btn-danger.btn-sm type="button" ng-model="status" btn-radio="'expired'" Expired
button.btn.btn-danger.btn-sm type="button" ng-model="status" btn-radio="'revoked'" Revoked
button.btn.btn-sm.btn-default type="button" ng-model="status" btn-radio="null" All
button.btn.btn-sm.btn-success type="button" ng-model="status" btn-radio="'active'" Active
button.btn.btn-sm.btn-info type="button" ng-model="status" btn-radio="'potential'" Potential
button.btn.btn-sm.btn-warning type="button" ng-model="status" btn-radio="'inactive'" Inactive
button.btn.btn-sm.btn-danger type="button" ng-model="status" btn-radio="'expired'" Expired
button.btn.btn-sm.btn-danger type="button" ng-model="status" btn-radio="'revoked'" Revoked

hr

/ top pagination for good measure
.text-center
pager ng-show="!loadingTracker.active()" total-items="filtered.length" page="currentPage" items-per-page="itemsPerPage"
pager total-items="filtered.length" page="currentPage" items-per-page="itemsPerPage"

/ user table
.table-responsive
Expand All @@ -63,7 +61,7 @@ div ng-controller="adminUserCtrl"
th style="width: 5%;" Exec
th Roles
tbody
tr.ng-cloak ng-repeat="user in filtered = (users | filter:status:true | filter:search) | startFrom:(currentPage-1)*itemsPerPage | limitTo:itemsPerPage"
tr.ng-cloak ng-repeat="user in filtered = (users | filter:status:true | filter:search | filter:filterByRole) | startFrom:(currentPage-1)*itemsPerPage | limitTo:itemsPerPage"
td
a ng-href="/admin/users/{{ user.id }}/edit" = "{{ user.username }}"
td = "{{ user.name }}"
Expand Down Expand Up @@ -91,7 +89,4 @@ div ng-controller="adminUserCtrl"

/ bottom pagination
.text-center
pagination ng-show="!loadingTracker.active()" total-items="filtered.length" page="currentPage" max-size="maxSize" boundary-links="true" items-per-page="itemsPerPage" rotate="false"


/= will_paginate @contests, renderer: BootstrapPagination::Rails, bootstrap: 3
pagination total-items="filtered.length" page="currentPage" max-size="maxSize" boundary-links="true" items-per-page="itemsPerPage" rotate="false"
50 changes: 33 additions & 17 deletions app/views/devise/registrations/edit.html.slim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
- defaults = {input_wrapper_html: {class: 'col-sm-7'}, label_html: {class: 'col-sm-3'}}
- defaults = {input_wrapper_html: {class: 'col-sm-6'}, label_html: {class: 'col-sm-4'}}

.page-header
h2 Edit Profile
Expand All @@ -9,45 +9,61 @@
.row
.col-sm-6
.form-group
= f.label "Avatar", class: 'col-sm-3'
= f.label "Avatar", class: 'col-sm-4'
.col-sm-3
= image_tag @user.avatar.url(:small), class: 'img-rounded'
.col-sm-6
- if @user.avatar.exists?
.col-sm-3
= f.input_field :delete_avatar, as: :boolean, inline_label: 'Remove Avatar'
- else
.col-sm-3
.text-center
p.text-muted
span express urself
br
span upload an avatar
p.text-danger
span.glyphicon.glyphicon-heart
.form-group
.col-sm-4.col-sm-offset-4
= f.file_field :avatar
= f.input_field :delete_avatar, as: :boolean, inline_label: 'Remove Avatar'
= f.input :first_name, autofocus: true, input_html: { class: 'form-control' }
= f.input :current_password, autofocus: true, input_html: { class: 'form-control' }, required: true
= f.input :first_name, input_html: { class: 'form-control' }
= f.input :middle_name, input_html: { class: 'form-control' }
= f.input :last_name, input_html: { class: 'form-control' }
= f.input :display_name, input_html: { class: 'form-control' }, hint: 'Not really being used yet, but set this if you want your name to be displayed differently on wrek.org and other public areas.'
= f.input :phone, input_html: { class: 'form-control' }
= f.input :birthday_string, input_html: { class: 'form-control' }
.form-group.hidden-xs
.col-sm-offset-3.col-sm-9
.col-sm-offset-4.col-sm-8
= f.button :submit, 'Update', class: 'btn-primary btn-lg'
.col-sm-6
= f.input :email, input_html: { class: 'form-control' }
= f.association :parent_op, collection: (User.all - [@user]), value_method: :id, label_method: :name_with_username, input_html: { class: 'form-control' }
.form-group
= f.label 'Subscriptions', class: 'col-sm-3'
= f.label 'Subscriptions', class: 'col-sm-4'
.col-sm-6
= f.input_field :subscribed_to_announce, inline_label: 'Announce List'
= f.input_field :subscribed_to_staff, inline_label: 'Staff List ([email protected])'
- if @user.potential?
p.text-muted As a potential, you're also subscribed to [email protected].
= f.input :password, input_html: { class: 'form-control' }
= f.input :password_confirmation, input_html: { class: 'form-control' }
hr
= f.input :password, label: 'New password', input_html: { class: 'form-control' }
= f.input :password_confirmation, label: 'Verify password', input_html: { class: 'form-control' }
hr
= f.simple_fields_for :legacy_profile do |p|
= p.input :buzzcard_id, input_html: { class: 'form-control' }
= p.input :buzzcard_fc, input_html: { class: 'form-control' }, hint: "We use BuzzCards for door access. #{link_to 'Help!', 'http://wrektranet.wrek.org/wiki/BuzzCardAccess'}".html_safe
hr
.form-group
.col-sm-6.col-sm-offset-3
.text-danger
= f.input_field :mark_as_inactive, as: :boolean, inline_label: 'Mark me as inactive.'
- unless @user.potential?
p.text-muted You will still need to unsubscribe from any lists above.
- else
p.text-muted You will no longer receive emails for [email protected].
- unless @user.expired? or @user.revoked? or @user.inactive?
.form-group
.col-sm-6.col-sm-offset-4
.text-danger
= f.input_field :mark_as_inactive, as: :boolean, inline_label: 'Mark me as inactive.'
- unless @user.potential?
p.text-muted You will still need to unsubscribe from any lists above.
- else
p.text-muted You will no longer receive emails for [email protected].
.form-group.visible-xs
.col-sm-offset-3.col-sm-9
= f.button :submit, 'Update', class: 'btn-primary btn-lg'
2 changes: 1 addition & 1 deletion app/views/layouts/_navigation.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
a.dropdown-toggle data-toggle="dropdown" href="#"
i.glyphicon.glyphicon-user>
strong> = current_user.username
span.text-muted = "- #{current_user.name}"
span.text-muted.hidden-sm.hidden-xs = "- #{current_user.name}"
b.caret
ul.dropdown-menu
- if Settings.profiles_enabled?
Expand Down
Loading

0 comments on commit 441e85e

Please sign in to comment.