Skip to content

Commit

Permalink
Asi 08 04 changes (#256)
Browse files Browse the repository at this point in the history
* last commit

* latest check

* new db migrations and updated passport

* login with drupal support

* add the rest, and lint

* GUI changes

* not sure how does res reach here

* that cache again

* cleanup

* remove code duplication

* fix lint

* adding error handling

* pass the error handling on

* fixed constants.js

* tmp disable travis cache for node_modules

* Update passport.js

* update to latest

* adding test special case

* no yoda notation for me T_T

* Update main_routes.test.js

* dddd

* update test-user and raise timeout

* update test-user and omit some test logic to adjust to new bizlogic of login

* changed the test user no need for mock anymore

* remove underscore

* updated imported csv to new members_camp

* commit changes

* d

* fixed the validated sign

* some fixes, adding the EVENT_ID

* removed the campDetails from all places.
fixed one insert and update.
update on new camp the event_id

* fix for eslint

* fixes

* fixed for eslint

* local commit

* added enabled status

* refine

* Merge branch 'master' of https://github.com/Midburn/Spark

* camps route fix

* Revert "camps route fix"

This reverts commit d926484.

* basic members implementation

* bug fix

* add member form

* removed unnecessary function call

* fixed several small issues, with getUserCamps functions, moving the functionality from API to the User model.

* fixed several small issues, with getUserCamps functions, moving the functionality from API to the User model.

* manually loaded api_camps_route

* test

* fix

* sdfsadf

* change activity time to multi select

* lilach location fixes

* improve contact person dropdown display

* facebook link size fix

* data validation

* lint

* Changed the API commands for join & join_deliver to work with the model commands.

* fix lint issues

* added option to remove approve new members

* lint

* fixed some bugs with getUserCamps and fix security issues.

* ui fixes

* commit passport + approve

* ddd

* changes

* join camp is according to lang

* FB link doesn't get too long

* translation fixes

* added approve join request btn

* added email templates

* comit local changes

* changes of field names for members

* typo fix

* updated the join camp flow, and tested

* lint shit

* lint shit

* fixes the join system, and several bug fix

* lint shit

* finalized the join flow
several bug was removed.
still having angular issue, need to be found.

* removed junk

* lint

* fixes issues before production, also import bugs.

* show contact information good

* d

* changes for lint

* small issues

* fixed the cancel user request
fixed some small security issues with users
removed automatic fetch from camps_v2
added language string for all status code.

* lint shit

* Introduced the camp __prototype to use for other camp types.
fixed the camp_location_area

* fixing all hebrew titles
fixed who am i
introduced the camp_type schema

* lint shit

* changes

* fixes split issue

* template api_gate

* fixed the members add, for admin
show all camps

* lint

* fixed mail delivery to join request

* lint

* refactoring edit + new, to fix foreign key, and adding fields to edit only for admin

* fixed add new camp, and adding default member.
todo:
after success update, forward to edit camp
check if camp_name hebrew + english are not empty
change selection of camp manager to be select2 input

* lint

* lint

* lint

* lint fixes

* lint

* latest fixes
  • Loading branch information
asihud authored Apr 8, 2017
1 parent 5091a9a commit 51ffef1
Show file tree
Hide file tree
Showing 8 changed files with 227 additions and 207 deletions.
18 changes: 18 additions & 0 deletions libs/common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
var functions = {
__hasRole: function (role, roles) {
return (roles && roles.split(',').indexOf(role) > -1);
},
__updateUserRec: function (user) {
if (!user.name && (user.first_name || user.last_name)) {
user.name = user.first_name + ' ' + user.last_name;
}
if (!user.name) {
user.name = user.email;
}
},
}

// Create the model and expose it
module.exports = {
common: functions,
};
19 changes: 4 additions & 15 deletions models/camp.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
// var i18next = require('i18next');
// var config = require('config');
// var i18nConfig = config.get('i18n');
const common = require('../libs/common').common;
var bookshelf = require('../libs/db').bookshelf;
var constants = require('./constants.js');
var User = require('../models/user').User;
const knex = require('../libs/db').knex;

function __hasRole(role, roles) {
return (roles && roles.split(',').indexOf(role) > -1);
}

var Camp = bookshelf.Model.extend({
tableName: constants.CAMPS_TABLE_NAME,
idAttribute: 'id',
Expand Down Expand Up @@ -39,17 +33,12 @@ var Camp = bookshelf.Model.extend({
if (t !== undefined) { // translate function
users[i].member_status_i18n = t('camps:members.status_' + _status);
}
common.__updateUserRec(users[i]);
users[i].can_remove = ['rejected', 'pending_mgr',].indexOf(_status) > -1;
users[i].can_approve = ['pending', 'rejected'].indexOf(_status) > -1 && users[i].validated;
users[i].can_reject = ['pending', 'approved'].indexOf(_status) > -1 && _this.attributes.main_contact !== users[i].user_id;

if (!users[i].name && (users[i].first_name || users[i].last_name)) {
users[i].name = users[i].first_name + ' ' + users[i].last_name;
}
if (!users[i].name) {
users[i].name = users[i].email;
}
if (((_this.attributes.main_contact === users[i].user_id || __hasRole('camp_manager', users[i].roles))

if (((_this.attributes.main_contact === users[i].user_id || common.__hasRole('camp_manager', users[i].roles))
&& users[i].member_status === 'approved')
|| (users[i].member_status === 'approved_mgr')) {
users[i].isManager = true;
Expand Down
20 changes: 0 additions & 20 deletions models/camp_member.js

This file was deleted.

11 changes: 3 additions & 8 deletions models/user.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const common = require('../libs/common').common;
var bookshelf = require('../libs/db').bookshelf;
var bcrypt = require('bcrypt-nodejs');
var randtoken = require('rand-token');
Expand Down Expand Up @@ -55,7 +56,6 @@ var User = bookshelf.Model.extend({
var first_camp;
var is_manager = false;
var member_type_array = ['approved', 'pending', 'pending_mgr', 'approved_mgr', 'supplier'];
// i18next.init({lng:'he'});
for (var i in camps) {
let _status = camps[i].member_status;
if (t !== undefined) { // translate function
Expand All @@ -64,11 +64,9 @@ var User = bookshelf.Model.extend({
if (!first_camp && member_type_array.indexOf(_status) > -1) {
first_camp = camps[i];
}
if (((camps[i].main_contact === this.attributes.user_id || this.__hasRole('camp_manager', this.attributes.roles))
if (((camps[i].main_contact === this.attributes.user_id || common.__hasRole('camp_manager', this.attributes.roles))
&& camps[i].member_status === 'approved')
|| (camps[i].member_status === 'approved_mgr')) {
// if ((camps[i].main_contact === this.attributes.user_id && camps[i].member_status === 'approved') ||
// camps[i].member_status === 'approved_mgr') {
first_camp = camps[i];
is_manager = true;
break;
Expand All @@ -85,11 +83,8 @@ var User = bookshelf.Model.extend({
validPassword: function (password) {
return bcrypt.compareSync(password, this.attributes.password);
},
__hasRole: function (role, roles) {
return (roles && roles.split(',').indexOf(role) > -1);
},
hasRole: function (role) {
return this.__hasRole(role, this.attributes.roles);
return common.__hasRole(role, this.attributes.roles);
},
isManagerOfCamp: function (camp_id) {
let isCampManager = false;
Expand Down
98 changes: 49 additions & 49 deletions public/scripts/camps.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
/**
* GLOBALS
*/
$(document).ajaxStart(function() {
$(document).ajaxStart(function () {
$('#ajax_indicator').removeClass('done').removeClass('hide').fadeIn('fast');
});
$(document).ajaxComplete(function() {
$(document).ajaxComplete(function () {
$('#ajax_indicator').addClass('done').fadeOut('slow');
});
$(function() {
$(function () {
// tooltips
$('[data-toggle="tooltip"]').tooltip()
});

/**
* Scroll to top - footer button
*/
$('#scroll_top').click(function() {
$('#scroll_top').click(function () {
$("html, body").stop().animate({
scrollTop: 0
}, '250', 'swing');
Expand All @@ -28,12 +28,12 @@ var interval = 800,
typingTimer,
$input = $(".camps input[name='camp_name_en']");

$input.keyup(function() {
$input.keyup(function () {
clearTimeout(typingTimer);
typingTimer = setTimeout(doneTyping, interval);
});

$input.keydown(function() {
$input.keydown(function () {
clearTimeout(typingTimer);
});

Expand All @@ -45,7 +45,7 @@ function doneTyping() {
btn = $('#check_camp_name');
if (val.length > 3) {
var data = $.get('../camps/' + val);
data.done(function() {
data.done(function () {
if (data.status === 204) {
input.removeClass('error');
status.removeClass('glyphicon-remove').addClass('glyphicon-ok');
Expand All @@ -64,7 +64,7 @@ function doneTyping() {

function getUserTemplate(data) {
if (data !== undefined) {
return "<option value='" + data.user_id + "'>" + data.fullName + "</option>"
return "<option value='" + data.user_id + "'>" + data.fullName + "</option>"
}
}
/**
Expand All @@ -76,36 +76,36 @@ function fetchUsersOnce(elm) {
elm = $(elm)

if (!elm.attr('fetched')) {
$.getJSON('/camps/' + camp_id + '/members', function(data) {})
.success((data) => {
users = [data.users];
for (var i = 0; i < users.length; i++) {
elm.append(getUserTemplate(users[i]));
}
})
.error((data) => {
if (lang === 'he') {
sweetAlert("אופס...", "אין משתמשים פעילים!", "error");
} else {
sweetAlert("Oops...", "No user available!", "error");
}
})
$.getJSON('/camps/' + camp_id + '/members', function (data) { })
.success((data) => {
users = [data.users];
for (var i = 0; i < users.length; i++) {
elm.append(getUserTemplate(users[i]));
}
})
.error((data) => {
if (lang === 'he') {
sweetAlert("אופס...", "אין משתמשים פעילים!", "error");
} else {
sweetAlert("Oops...", "No user available!", "error");
}
})

elm.attr('fetched', true);
}
}
$(function() {
$(function () {
var user_inputs = '#create_camp_contact_person_id';
if ($('.camps').is('.camp_create')) {
fetchUsersOnce(user_inputs);
fetchUsersOnce(user_inputs);
}
});

/**
* Component: Editing camp
* (PUT) /camps/:camp_id/edit
*/
$('#camp_edit_save').click(function() {
$('#camp_edit_save').click(function () {
var lang = document.getElementById('meta__lang').value;
var type = fetchAllCheckboxValues('camp_type');
var activity_time = fetchAllCheckboxValues('camp_activity_time');
Expand Down Expand Up @@ -141,42 +141,42 @@ $('#camp_edit_save').click(function() {
url: '/camps/' + camp_id + '/edit',
type: 'PUT',
data: camp_data,
success: function(result) {
if (lang ==='he') {
success: function (result) {
if (lang === 'he') {
sweetAlert("כל הכבוד", "המחנה עודכן, על מנת לראות את השינויים יש לרענן את העמוד", "success");
} else {
sweetAlert("You good...", "Camp details updated! reload the page.", "success");
}
}
});
});
$('#camp_edit_publish').click(function() {
$('#camp_edit_publish').click(function () {
var camp_id = $('#camp_edit_camp_id').val();
$.ajax({
url: '/camps/' + camp_id + '/publish',
type: 'PUT',
success: function(result) {
success: function (result) {
console.log(result);
}
});
});
$('#camp_edit_unpublish').click(function() {
$('#camp_edit_unpublish').click(function () {
var camp_name = $('#meta__camp_name_en').attr('value'),
agree_unpublish = confirm('Un-publish camp\n\n\nThis action will remove ' + camp_name + ' from the public camps list.\n\n\n---\n Are you sure?');
if (agree_unpublish) {
var camp_id = $('#camp_edit_camp_id').val();
$.ajax({
url: '/camps/' + camp_id + '/unpublish',
type: 'PUT',
success: function(result) {
success: function (result) {
console.log(result);
}
});
}
});

// display other text field if other selected
$('#edit_type_other').click(function() {
$('#edit_type_other').click(function () {
if ($('#edit_type_other').is(':checked')) {
$('#edit_type_other_text').removeClass('hidden');
} else {
Expand All @@ -187,7 +187,7 @@ $('#edit_type_other').click(function() {
/**
* Component: Create new camp with approval modal
*/
$('#camp_create_save').click(function() {
$('#camp_create_save').click(function () {
var type = fetchAllCheckboxValues('camp_type');
var activity_time = fetchAllCheckboxValues('camp_activity_time');
var camp_data = {
Expand Down Expand Up @@ -221,12 +221,12 @@ $('#camp_create_save').click(function() {
$('#create_camp_request_modal').modal('show');
_campAppendData();
// approve create camp
$('#camp_create_save_modal_request').click(function() {
$('#camp_create_save_modal_request').click(function () {
_sendRequest();
});

function _campAppendData() {
$.each(camp_data, function(label, data) {
$.each(camp_data, function (label, data) {
if (data) {
$('.' + label).show();
$('.' + label + ' span').text(': ' + data).css('font-weight', 'bold');
Expand All @@ -242,17 +242,17 @@ $('#camp_create_save').click(function() {
url: '/camps/new',
type: 'POST',
data: camp_data,
success: function(result) {
success: function (result) {
var camp_id = result.data.camp_id;
$('#create_camp_request_modal').find('.modal-body').html('<h4>Camp created succesfully. <br><span class="Btn Btn__sm Btn__inline">you can edit it: <a href="' + [window.location.origin, $('body').attr('lang')].join('/') + '/camps/' + camp_id + '/edit">here</a><span></h4>');
$('#create_camp_request_modal').find('#camp_create_save_modal_request').hide();
// 10 sec countdown to close modal
var sec = 10;
setInterval(function() {
setInterval(function () {
$('#create_camp_request_modal').find('#create_camp_close_btn').text('Close ' + sec);
sec -= 1;
}, 1000);
setTimeout(function() {
setTimeout(function () {
$('#create_camp_request_modal').modal('hide');
}, sec * 1000);
}
Expand All @@ -261,7 +261,7 @@ $('#camp_create_save').click(function() {
});

// display other text field if other selected
$('#camp_type_other_checkbox').click(function() {
$('#camp_type_other_checkbox').click(function () {
if ($('#camp_type_other_checkbox').is(':checked')) {
$('#camp_type_other_text').removeClass('hidden');
} else {
Expand All @@ -271,22 +271,22 @@ $('#camp_type_other_checkbox').click(function() {

// Collect all checkbox values
function fetchAllCheckboxValues(className) {
var val = [];
$('.' + className + ':checked').each(function(i) {
val[i] = $(this).val();
if (val[i] === 'other') {
val[i] += '=' + $('#'+ className + '_other_text').val()
}
});
return val.toString();
var val = [];
$('.' + className + ':checked').each(function (i) {
val[i] = $(this).val();
if (val[i] === 'other') {
val[i] += '=' + $('#' + className + '_other_text').val()
}
});
return val.toString();
}
/*
* Component: view camp details
*/
// Fetch & inject user data
var user_type;
function _fetchUserData(user_id) {
$.getJSON('/users/' + user_id, function(response) {
$.getJSON('/users/' + user_id, function (response) {
_injectUserData(response)
})
}
Expand All @@ -301,7 +301,7 @@ function _injectUserData(user_data) {
$(type).removeClass('hidden').fadeIn('fast');
}
if ($('.camp_details')) {
$('.fetch_user_info').click(function() {
$('.fetch_user_info').click(function () {
var user_id = $(this).attr('data-user-id')
user_type = $(this).attr('data-user-type');
_fetchUserData(user_id);
Expand Down
Loading

0 comments on commit 51ffef1

Please sign in to comment.