Skip to content

Commit

Permalink
Merge pull request #434 from Midburn/asi-groups-latest-fixes-20-05
Browse files Browse the repository at this point in the history
Asi groups latest fixes 20 05
  • Loading branch information
LeonFedotov authored May 21, 2017
2 parents 7c0d617 + fb477c5 commit 5b504e8
Show file tree
Hide file tree
Showing 10 changed files with 151 additions and 58 deletions.
2 changes: 1 addition & 1 deletion libs/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ var functions = {
if (filter.test(user_email)) {
return user_email;
}
}
},
}

// Create the model and expose it
Expand Down
24 changes: 13 additions & 11 deletions models/camp.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ var Camp = bookshelf.Model.extend({

// let _camps_members = constants.CAMP_MEMBERS_TABLE_NAME;
// let _users = constants.USERS_TABLE_NAME;
//,SUM(tickets.inside_event) AS inside_event
let query="SELECT users.*,camp_members.status AS member_status,SUM(IF(tickets.ticket_id>0,1,0)) AS ticket_count,SUM(tickets.inside_event) AS inside_event FROM users inner join camp_members on users.user_id=camp_members.user_id left join tickets on tickets.holder_id=users.user_id and tickets.event_id='MIDBURN2017' where camp_members.camp_id="+this.attributes.id+" group by users.user_id";
let query = "SELECT users.*,camp_members.status AS member_status,SUM(IF(tickets.ticket_id>0,1,0)) AS ticket_count,SUM(tickets.inside_event) AS inside_event FROM users inner join camp_members on users.user_id=camp_members.user_id left join tickets on tickets.holder_id=users.user_id and tickets.event_id='MIDBURN2017' where camp_members.camp_id=" + this.attributes.id + " group by users.user_id";
return knex //(_users)
.raw(query)
// .select(_users + '.*', _camps_members + '.status AS member_status'/*,'tickets.ticket_id'*/)
Expand All @@ -44,8 +43,7 @@ var Camp = bookshelf.Model.extend({
// .leftjoin('tickets','tickets.holder_id','users.user_id')
// .where({ 'camp_members.camp_id': this.attributes.id })
.then((users_raw_data) => {
let users=users_raw_data[0];
// console.log(users);
let users = users_raw_data[0];
let managers = [];
// let emails
for (let i in users) {
Expand Down Expand Up @@ -116,28 +114,32 @@ var Camp = bookshelf.Model.extend({
this.attributes.camp_desc_en_linkify = common.linkify(this.attributes.camp_desc_en);
}
},
__parsePrototype: function (prototype, user) {
__parsePrototype: function(prototype, user) {
let result = constants.prototype_camps.by_prototype(prototype);
if (!result) return false;
let isAdmin = false;
let t_prefix = '';
if (user instanceof User) {
isAdmin = user.isAdmin;
if (this.attributes.__prototype === constants.prototype_camps.THEME_CAMP.id) {
isAdmin = isAdmin || req.user.isCampsAdmin;
if (prototype === constants.prototype_camps.THEME_CAMP.id) {
isAdmin = isAdmin || user.isCampsAdmin;
t_prefix = 'camps:';
} else if (this.attributes.__prototype === constants.prototype_camps.ART_INSTALLATION.id) {
isAdmin = isAdmin || req.user.isArtInstallationsAdmin;
} else if (prototype === constants.prototype_camps.ART_INSTALLATION.id) {
isAdmin = isAdmin || user.isArtInstallationsAdmin;
t_prefix = 'camps:art_installation.';
} else if (this.attributes.__prototype === constants.prototype_camps.PROD_DEP.id) {
isAdmin = isAdmin || req.user.isProdDepsAdmin;
} else if (prototype === constants.prototype_camps.PROD_DEP.id) {
isAdmin = isAdmin || user.isProdDepsAdmin;
t_prefix = 'camps:prod_dep.';
}
}
result.isAdmin = isAdmin;
result.t_prefix = t_prefix;
return result;
},

parsePrototype: function (user) {
return this.__parsePrototype(this.attributes.__prototype, user);
},
virtuals: {
managers: function () {
return this.attributes.managers;
Expand Down
6 changes: 1 addition & 5 deletions models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,6 @@ var User = bookshelf.Model.extend({
}
if (req && typeof (req) === 'object' && typeof (req['t']) === 'function') {
t = req.t;
// if (req['user']) {
// _current_user = req.user;
// }
}
var _camps_members = constants.CAMP_MEMBERS_TABLE_NAME;
var _camps = constants.CAMPS_TABLE_NAME;
Expand All @@ -117,7 +114,6 @@ var User = bookshelf.Model.extend({
'camps.event_id': constants.CURRENT_EVENT_ID,
};
if (prototype!=='all') _where['__prototype']=prototype;
console.log(_where);
knex(_camps)
.select(_camps + '.*', _camps_members + '.status AS member_status', 'users_groups.entrance_quota')
.innerJoin(_camps_members, _camps + '.id', _camps_members + '.camp_id')
Expand All @@ -140,7 +136,7 @@ var User = bookshelf.Model.extend({
|| (camps[i].member_status === 'approved_mgr'))) {
first_camp = camps[i];
is_manager = true;
break;
// break;
}
}
_this_user.attributes.camps = camps;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"this is part of the deployment proess, so it is important to update the version number",
"version name corresponds to the github release name / tag name - https://github.com/Midburn/Spark/releases"
],
"version": "2.6.0",
"version": "2.6.1",
"private": true,
"scripts": {
"postinstall": "bower install",
Expand Down
41 changes: 25 additions & 16 deletions public/scripts/controllers/camp_edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ var angular_getMembers = function ($http, $scope, camp_id) {
if (['approved', 'approved_mgr'].indexOf(members[i].member_status) > -1) {
approved_members.push(members[i]);
}
total_in_event+=parseInt(members[i].inside_event);
total_camp_tickets+=parseInt(members[i].ticket_count) || 0;
total_in_event += parseInt(members[i].inside_event);
total_camp_tickets += parseInt(members[i].ticket_count) || 0;
}
$scope.members = _members;
$scope.approved_members = approved_members;
Expand All @@ -37,7 +37,7 @@ var angular_updateUser = function ($http, $scope, action_type, user_rec) {
if (lang === undefined) {
lang = 'he';
}
var tpl,action_tpl;
var tpl, action_tpl;

if (lang === "he") {
// debugger;
Expand Down Expand Up @@ -100,23 +100,23 @@ app.controller("campEditController", ($scope, $http, $filter) => {
}
if (lang === "he") {
$scope.status_options = [
{id:'open',value:'מחנה פתוח למצטרפים חדשים'},
{id:'closed',value:'סגור למצטרפים חדשים'}];
{ id: 'open', value: 'מחנה פתוח למצטרפים חדשים' },
{ id: 'closed', value: 'סגור למצטרפים חדשים' }];
$scope.noise_level_options = [
{id:'quiet',value:'שקט'},
{id:'medium',value:'בינוני'},
{id:'noisy',value:'רועש'},
{id:'very noisy',value:'מאוד רועש'} ];
{ id: 'quiet', value: 'שקט' },
{ id: 'medium', value: 'בינוני' },
{ id: 'noisy', value: 'רועש' },
{ id: 'very noisy', value: 'מאוד רועש' }];
} else {
$scope.status_options = ['Opened to new member', 'Closed to new members'];
$scope.status_options = [
{id:'open',value:'Opened to new member'},
{id:'closed',value:'Closed to new members'}];
{ id: 'open', value: 'Opened to new member' },
{ id: 'closed', value: 'Closed to new members' }];
$scope.noise_level_options = [
{id:'quiet',value:'Quiet'},
{id:'medium',value:'Medium'},
{id:'noisy',value:'Noisy'},
{id:'very noisy',value:'Very Noisy'} ];
{ id: 'quiet', value: 'Quiet' },
{ id: 'medium', value: 'Medium' },
{ id: 'noisy', value: 'Noisy' },
{ id: 'very noisy', value: 'Very Noisy' }];
}

$scope.getMembers = () => {
Expand Down Expand Up @@ -144,7 +144,7 @@ app.controller("campEditController", ($scope, $http, $filter) => {
$http.post(`/camps/${camp_id}/members/add`, data).then(function (res) {
// update table with new data
$scope.getMembers();
$scope.camps_members_add_member='';
$scope.camps_members_add_member = '';
}).catch((err) => {
sweetAlert("Error!", "Add new member error: " + err.data.data.message, "error");
});
Expand All @@ -158,5 +158,14 @@ app.controller("campEditController", ($scope, $http, $filter) => {
}
angular_updateUser($http, $scope, action_type, user_rec);
}
});

app.controller("homeController", ($scope, $http, $filter) => {
$scope.angular_getMyGroups = function ($http, $scope) {
$http.get(`/my_groups`).then((res) => {
// debugger;
$scope.groups = res.data.groups;
});
}
$scope.angular_getMyGroups($http, $scope);
});
44 changes: 35 additions & 9 deletions routes/api_camps_routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ var __camps_update_status = (camp_id, user_id, action, camp_mgr, res) => {
} else {
camp_mgr_id = parseInt(camp_mgr);
}
group_options = camp.__parsePrototype(camp.attributes.__prototype, camp_mgr);
console.log(group_options);
group_options = camp.parsePrototype(camp_mgr);
let isAdmin = group_options.isAdmin;
console.log(action + " from camp " + camp_id + " of user " + user_id + " / mgr id: " + camp_mgr_id);

Expand Down Expand Up @@ -224,10 +223,7 @@ module.exports = (app, passport) => {
} else if (typeof (camp) === 'string' && camp !== '') {
prototype = camp;
} else prototype = constants.prototype_camps.THEME_CAMP.id;

group_props = Camp.forge().__parsePrototype(prototype, req.user);

// group_props=camp.__parsePrototype(camp.attribu)}
group_props = Camp.prototype.__parsePrototype(prototype, req.user);
var data = {
event_id: constants.CURRENT_EVENT_ID,
// for update or insert, need to merge with create to be the same call
Expand Down Expand Up @@ -424,7 +420,7 @@ module.exports = (app, passport) => {
.fetch({ withRelated: ['users_groups'] })
.then((camp) => {
camp.getCampUsers((users) => {
group_props = camp.__parsePrototype(camp.attributes.__prototype, req.user);
group_props = camp.parsePrototype(req.user);
if (camp.isCampManager(req.user.attributes.user_id) || group_props.isAdmin) {
__camps_save(req, false, camp)
// Camp.forge({ id: req.params.id }).fetch().then((camp) => {
Expand Down Expand Up @@ -874,7 +870,7 @@ module.exports = (app, passport) => {
return member;
});
}
result = camp.__parsePrototype(camp.attributes.__prototype, req.user);
result = camp.parsePrototype(req.user);

if (isCampManager || (result && result.isAdmin)) {
res.status(200).json({ members: members });
Expand All @@ -896,6 +892,36 @@ module.exports = (app, passport) => {
});
});

app.get('/my_groups',userRole.isLoggedIn(), (req, res) => {
req.user.getUserCamps((camps) => {
let groups=[];
let group={};
let group_props;
// console.log(camps);
for (let i in camps) {
group_props=Camp.prototype.__parsePrototype(camps[i].__prototype,req.user);
if (['approved','pending','pending_mgr','approved_mgr'].indexOf(camps[i].member_status)>-1) {
group={
// group_type:'מחנה נושא',
group_id: camps[i].id,
group_type: req.t(group_props.t_prefix+'edit.camp'),
member_status: camps[i].member_status,
member_status_i18n: camps[i].member_status_i18n,
camp_desc_i18n: camps[i].camp_name_he,
camp_desc_he: camps[i].camp_name_he,
camp_name_en: camps[i].camp_name_en,
can_view: ['theme_camp'].indexOf(camps[i].__prototype)>-1,
can_edit: camps[i].isManager,
is_manager_i18n: camps[i].isManager?req.t('camps:yes'):req.t('camps:no'),
};
groups.push(group);
}
}
// console.log(groups);
res.status(200).json({ groups: groups });
}, req, 'all');
});

/**
* API: (POST) camp manager send member join request
* request => /camps/1/members/add
Expand All @@ -913,7 +939,7 @@ module.exports = (app, passport) => {
return;
}
req.user.getUserCamps((camps) => {
let group_props = camp.__parsePrototype(camp.attributes.__prototype, req.user);
let group_props = camp.parsePrototype(req.user);
if (req.user.isManagerOfCamp(camp_id) || group_props.isAdmin) {
User.forge({ email: user_email }).fetch().then((user) => {
if (user !== null) {
Expand Down
14 changes: 9 additions & 5 deletions routes/camps_routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ module.exports = function (app, passport) {
}]);

let prototype = constants.prototype_camps.THEME_CAMP.id;
let result = Camp.__parsePrototype(prototype, req.user);
let result = Camp.prototype.__parsePrototype(prototype, req.user);
res.render('pages/camps/edit', {
user: req.user,
camp_name_en: req.query.c,
Expand Down Expand Up @@ -158,7 +158,7 @@ module.exports = function (app, passport) {
}).then((camp) => {
req.user.getUserCamps((camps) => {
// let __groups_prototype='';
let result = camp.__parsePrototype(camp.attributes.__prototype, req.user);
let result = camp.parsePrototype(req.user);
if (req.user.isManagerOfCamp(req.params.id) || result.isAdmin) {
let camp_data = __camp_data_to_json(camp);
if (camp_data.addinfo_json !== null) {
Expand Down Expand Up @@ -262,7 +262,8 @@ module.exports = function (app, passport) {
user: req.user,
breadcrumbs: req.breadcrumbs(),
__groups_prototype: 'theme_camps',
t_prefix: 'camps:'
t_prefix: 'camps:',
isCamp: true,
});
} else {
// user not admin
Expand All @@ -288,7 +289,8 @@ module.exports = function (app, passport) {
user: req.user,
breadcrumbs: req.breadcrumbs(),
__groups_prototype: 'art_installation',
t_prefix: 'camps:art_installation.'
t_prefix: 'camps:art_installation.',
isArt: true,
});
} else {
// user not admin
Expand All @@ -313,7 +315,9 @@ module.exports = function (app, passport) {
user: req.user,
breadcrumbs: req.breadcrumbs(),
__groups_prototype: 'prod_dep',
t_prefix: 'camps:prod_dep.'
t_prefix: 'camps:prod_dep.',
isProd: true,

});
} else {
// user not admin
Expand Down
6 changes: 0 additions & 6 deletions routes/main_routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,10 @@ module.exports = function (app, passport) {
name: 'breadcrumbs.home',
url: '/' + req.params.lng + '/home'
});
req.user.getUserCamps((camps) => {
// console.log(camps);
// for (let i in camps) {
//
// }
res.render('pages/home', {
user: req.user,
breadcrumbs: req.breadcrumbs()
});
}, req, 'all');
});

// =====================================
Expand Down
10 changes: 6 additions & 4 deletions views/pages/camps/index_admin.jade
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ block content
div.input-group
a.Btn.Btn__default.card-switcher#1(href=`/${language}/camps-admin/manage`, role='button')=t(t_prefix+'admin_index.all_camps')
a.Btn.Btn__transparent.card-switcher#2(href=`/${language}/camps-admin/members`, role='button')=t(t_prefix+'admin_index.all_members')
a.Btn.Btn__transparent.card-switcher#3(href=`/${language}/camps-admin/docs`, role='button')=t(t_prefix+'admin_index.docs')
a.Btn.Btn__green.card-switcher#4(href=`/${language}/camps-admin/new`, role='button')
span.glyphicon.glyphicon-plus(aria-hidden="true")
span=t(t_prefix+'admin_index.new')
if isCamp
a.Btn.Btn__transparent.card-switcher#3(href=`/${language}/camps-admin/docs`, role='button')=t(t_prefix+'admin_index.docs')
if isCamp
a.Btn.Btn__green.card-switcher#4(href=`/${language}/camps-admin/new`, role='button')
span.glyphicon.glyphicon-plus(aria-hidden="true")
span=t(t_prefix+'admin_index.new')

.cards--wrapper.card__shad
//- Card 1
Expand Down
Loading

0 comments on commit 5b504e8

Please sign in to comment.