show only your office's supervisors

parent 054e9e17
...@@ -13,3 +13,5 @@ Database ...@@ -13,3 +13,5 @@ Database
`alter table supervisor add column `postal_code` char(10) COLLATE utf8_unicode_ci NOT NULL;` `alter table supervisor add column `postal_code` char(10) COLLATE utf8_unicode_ci NOT NULL;`
- copy postal_code value from office to its supervisors - copy postal_code value from office to its supervisors
`update supervisor as sup inner join office as off on off.id = sup.id_off set sup.postal_code = off.postal_code;` `update supervisor as sup inner join office as off on off.id = sup.id_off set sup.postal_code = off.postal_code;`
- alter table office
`alter table office modify logo_url varchar(240) default null;`
...@@ -100,7 +100,7 @@ module.exports = { ...@@ -100,7 +100,7 @@ module.exports = {
} }
if (!supervisor.isSupAdmin && !stuSup) if (!supervisor.isSupAdmin && !stuSup)
throw res.unauthorized("Supervisor without students"); return res.unauthorized("Supervisor without students");
return res.ok({ return res.ok({
user: supervisor, user: supervisor,
...@@ -108,7 +108,6 @@ module.exports = { ...@@ -108,7 +108,6 @@ module.exports = {
token: sailsTokenAuth.issueToken(supervisor, sails.config.jwt.expiresInMinutes) token: sailsTokenAuth.issueToken(supervisor, sails.config.jwt.expiresInMinutes)
}); });
}) })
.catch(function (err) { .catch(function (err) {
return res.serverError("Error when connecting to database"); return res.serverError("Error when connecting to database");
}); });
...@@ -186,7 +185,9 @@ module.exports = { ...@@ -186,7 +185,9 @@ module.exports = {
welcome_msg2: sails.__({ welcome_msg2: sails.__({
phrase: 'welcome_msg2', phrase: 'welcome_msg2',
locale: supervisor.lang locale: supervisor.lang
}, {login_url: 'https://' + req.headers.host + '/app'}) }),
login_url: 'https://' + req.headers.host + '/app',
login: sails.__('login')
}); });
}) })
...@@ -262,6 +263,8 @@ module.exports = { ...@@ -262,6 +263,8 @@ module.exports = {
// Send email confirmation // Send email confirmation
function sendConfirmationMail(cb) { function sendConfirmationMail(cb) {
console.log("mail------------\n" + JSON.stringify(supervisor));
var token = sailsTokenAuth.issueToken({ var token = sailsTokenAuth.issueToken({
id_sup: supervisor.id, id_sup: supervisor.id,
role: params.role, role: params.role,
...@@ -283,15 +286,14 @@ module.exports = { ...@@ -283,15 +286,14 @@ module.exports = {
}) })
.then(() => {cb();}) .then(() => {cb();})
.catch((err) => {cb(err);}); .catch((err) => {cb(err);});
} } // /sendConfirmationEmail()
sails.log.debug("Creating supervisor with params " + JSON.stringify(params)); sails.log.debug("Creating supervisor with params " + JSON.stringify(params));
if (!params.name || !params.surname || !params.gender || !params.password || !params.email ) if (!params.name || !params.surname || !params.gender || !params.password || !params.email )
res.badRequest("Invalid params"); res.badRequest("Invalid params");
var supData = {
Supervisor.create({
name: params.name, name: params.name,
surname: params.surname, surname: params.surname,
gender: params.gender, gender: params.gender,
...@@ -299,13 +301,17 @@ module.exports = { ...@@ -299,13 +301,17 @@ module.exports = {
email: params.email, email: params.email,
pic: sails.config.pictogram.paths.defaultAvatarFileName, pic: sails.config.pictogram.paths.defaultAvatarFileName,
address: params.address || '', address: params.address || '',
postal_code: params.postal_code || '', postalCode: params.postalCode || '',
country: params.country || null, country: params.country || '',
phone: params.phone || '', phone: params.phone || '',
lang: params.lang || 'es-es', lang: params.lang || 'es-es',
ttsEngine: params.ttsEngine || null, };
id_off: params.id_off || null if (params.id_off)
}) supData.id_off = params.id_off;
console.log("supData:\n" + JSON.stringify(supData));
Supervisor.create(supData)
.then(function (sup) { .then(function (sup) {
if (!sup) if (!sup)
...@@ -319,11 +325,19 @@ module.exports = { ...@@ -319,11 +325,19 @@ module.exports = {
return res.ok(); return res.ok();
}); });
} else if (params.role === 'therapist_nooffice' || params.role === 'tutor_nooffice') { } else if (params.role === 'therapist_nooffice' || params.role === 'tutor_nooffice') {
Office.create(params.office) Office.create(params.office)
.then((off) => { .then((off) => {
// link supervisor with office
supervisor.id_off = off.id; supervisor.id_off = off.id;
delete supervisor.password; delete supervisor.password;
supervisor.save(); supervisor.save();
// set supervisor as admin in the office
off.admin = supervisor.id;
off.save();
sendConfirmationMail((err) => { sendConfirmationMail((err) => {
if (err) throw err; if (err) throw err;
return res.ok(); return res.ok();
......
...@@ -26,15 +26,25 @@ module.exports = { ...@@ -26,15 +26,25 @@ module.exports = {
type: "string", type: "string",
size: 80 size: 80
}, },
logoUrl: {
columnName: 'logo_url',
type: "string",
size: 240
},
address: { address: {
required: true, required: true,
type: "string", type: "string",
size: 80 size: 80
}, },
logo_url: { country: {
required: true, type: "string",
type: "string", size: 5,
size: 240 required: true
},
lang: {
required: true,
type: "string",
size: 2
}, },
contactPerson: { contactPerson: {
columnName: "contact_person", columnName: "contact_person",
...@@ -57,29 +67,17 @@ module.exports = { ...@@ -57,29 +67,17 @@ module.exports = {
type: "string", type: "string",
size: 20 size: 20
}, },
lang: {
required: true,
type: "string",
size: 2
},
country: {
type: "string",
size: 5
},
maxStudents: {
columnName: "max_students",
type: "integer"
},
currentStudents: {
columnName: "current_students",
type: "integer"
},
admin: { admin: {
columnName: 'admin', columnName: 'admin',
required: true,
type: 'integer', type: 'integer',
model: 'Supervisor' model: 'Supervisor'
}, },
postalCode: {
columnName: 'postal_code',
required: true,
type: "string",
size: 10
},
// Relación con Teacher. [1 Office to N Teacher] // Relación con Teacher. [1 Office to N Teacher]
supervisors: { supervisors: {
collection: "Supervisor", collection: "Supervisor",
...@@ -90,5 +88,12 @@ module.exports = { ...@@ -90,5 +88,12 @@ module.exports = {
collection: "Student", collection: "Student",
via: 'office' via: 'office'
} }
},
beforeCreate: function (attrs, next) {
if (attrs.logoUrl)
attrs.logoUrl = '/app/img/logo_pictogram.png';
next();
} }
}; };
...@@ -52,7 +52,8 @@ module.exports = { ...@@ -52,7 +52,8 @@ module.exports = {
type: "string", type: "string",
size: 180 size: 180
}, },
postal_code: { postalCode: {
columnName: 'postal_code',
type: "string", type: "string",
size: 10 size: 10
}, },
......
...@@ -24,7 +24,7 @@ function LoginCtrl( ...@@ -24,7 +24,7 @@ function LoginCtrl(
}; };
$scope.office = { $scope.office = {
logo_url : 'img/logo_pictogram.png', logoUrl : 'img/logo_pictogram.png',
name : 'Pictogram' name : 'Pictogram'
}; };
...@@ -48,8 +48,8 @@ function LoginCtrl( ...@@ -48,8 +48,8 @@ function LoginCtrl(
data.user.isTutor = true; data.user.isTutor = true;
} else } else
data.user.isTutor = false; data.user.isTutor = false;
if (data.user.office.logo_url.length < 5) if (data.user.office.logoUrl.length < 5)
data.user.office.logo_url = 'img/logo_pictogram.png'; data.user.office.logoUrl = 'img/logo_pictogram.png';
$window.sessionStorage.token = data.token; $window.sessionStorage.token = data.token;
......
...@@ -34,11 +34,12 @@ function SignInCtrl($scope, ...@@ -34,11 +34,12 @@ function SignInCtrl($scope,
office: { office: {
name: '', name: '',
address: '', address: '',
postal_code: '', postalCode: '',
country: '00', country: '00',
contact_person: '', contactPerson: '',
phone: '', phone1: '',
email: '' email: '',
logoUrl: ''
}, },
office_idx: -1 office_idx: -1
}; };
...@@ -56,6 +57,17 @@ function SignInCtrl($scope, ...@@ -56,6 +57,17 @@ function SignInCtrl($scope,
ngToast.danger({ content: $translate.instant('server_error') }); ngToast.danger({ content: $translate.instant('server_error') });
}); });
// Copy fields from supervisor to office
$scope.copyFields = function () {
$scope.formdata.office.address = $scope.formdata.address;
$scope.formdata.office.postalCode = $scope.formdata.postalCode;
$scope.formdata.office.country = $scope.formdata.country;
$scope.formdata.office.lang = $scope.formdata.lang;
$scope.formdata.office.email = $scope.formdata.email;
$scope.formdata.office.phone1 = $scope.formdata.phone;
$scope.formdata.office.contactPerson = $scope.formdata.name + " " + $scope.formdata.surname;
};
// Form submit // Form submit
$scope.signin = function () { $scope.signin = function () {
// Validate email match // Validate email match
...@@ -108,11 +120,12 @@ function SignInCtrl($scope, ...@@ -108,11 +120,12 @@ function SignInCtrl($scope,
if ($scope.formdata.role === 'tutor_nooffice') { if ($scope.formdata.role === 'tutor_nooffice') {
$scope.formdata.office.name = $scope.formdata.name + " " + $scope.formdata.surname; $scope.formdata.office.name = $scope.formdata.name + " " + $scope.formdata.surname;
$scope.formdata.office.address = $scope.formdata.address; $scope.formdata.office.address = $scope.formdata.address;
$scope.formdata.office.postal_code = $scope.formdata.postal_code; $scope.formdata.office.postalCode = $scope.formdata.postalCode;
$scope.formdata.office.country = $scope.formdata.country; $scope.formdata.office.country = $scope.formdata.country;
$scope.formdata.office.contact_person = $scope.formdata.name + " " + $scope.formdata.surname; $scope.formdata.office.contactPerson = $scope.formdata.name + " " + $scope.formdata.surname;
$scope.formdata.office.phone = $scope.formdata.phone; $scope.formdata.office.phone1 = $scope.formdata.phone;
$scope.formdata.office.email = $scope.formdata.email; $scope.formdata.office.email = $scope.formdata.email;
$scope.formdata.office.lang = $scope.formdata.lang;
} }
$http $http
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
</p> </p>
--> -->
<p class="text-center"> <p class="text-center">
<img ng-src="{{office.logo_url}}" alt="{{office.name}}" title="{{office.name}}"> <img ng-src="{{office.logoUrl}}" alt="{{office.name}}" title="{{office.name}}">
</p> </p>
<!-- Formulario --> <!-- Formulario -->
<!-- LoginCtrl controls here, see app.js --> <!-- LoginCtrl controls here, see app.js -->
......
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
<div class="row"> <div class="row">
<div class="col-md-4"> <div class="col-md-4">
<div class="form-group"> <div class="form-group">
<input type="text" class="form-control" id="signin_postal_code" placeholder="{{ 'postal_code' | translate }}" required ng-model="formdata.postal_code" ng-change="formdata.postal_code = formdata.postal_code.toUpperCase()"/> <input type="text" class="form-control" id="signin_postal_code" placeholder="{{ 'postal_code' | translate }}" required ng-model="formdata.postalCode" ng-change="formdata.postalCode = formdata.postalCode.toUpperCase()"/>
</div> </div>
</div> </div>
<div class="col-md-8"> <div class="col-md-8">
...@@ -142,7 +142,8 @@ ...@@ -142,7 +142,8 @@
type="radio" type="radio"
ng-model="formdata.role" ng-model="formdata.role"
value="therapist_nooffice" value="therapist_nooffice"
onClick="$('#office_selection').slideUp(); $('#office_form').slideDown();"> onClick="$('#office_selection').slideUp(); $('#office_form').slideDown();"
ng-click="copyFields();">
</div> </div>
<div class="col-md-11"> <div class="col-md-11">
{{ 'case_therapist_nooffice' | translate }} {{ 'case_therapist_nooffice' | translate }}
...@@ -172,7 +173,8 @@ ...@@ -172,7 +173,8 @@
type="radio" type="radio"
ng-model="formdata.role" ng-model="formdata.role"
value="tutor_nooffice" value="tutor_nooffice"
onClick="$('#office_selection').slideUp(); $('#office_form').slideUp();"> onClick="$('#office_selection').slideUp(); $('#office_form').slideUp(); copyFields();"
ng-click="copyFields();">
</div> </div>
<div class="col-md-11"> <div class="col-md-11">
{{ 'case_tutor_nooffice' | translate }} {{ 'case_tutor_nooffice' | translate }}
...@@ -187,7 +189,7 @@ ...@@ -187,7 +189,7 @@
<input type="text" class="form-control" placeholder="{{ 'name' | translate }}" ng-model="formdata.office.name" ng-required="formdata.role == 'therapist_nooffice'"/> <input type="text" class="form-control" placeholder="{{ 'name' | translate }}" ng-model="formdata.office.name" ng-required="formdata.role == 'therapist_nooffice'"/>
</div> </div>
<div class="form-group"> <div class="form-group">
<input type="text" class="form-control" placeholder="{{ 'logo_url' | translate }}" ng-model="formdata.office.logo_url"/> <input type="text" class="form-control" placeholder="{{ 'logo_url' | translate }}" ng-model="formdata.office.logoUrl"/>
</div> </div>
<div class="form-group"> <div class="form-group">
<input type="text" class="form-control" placeholder="{{ 'address' | translate }}" ng-model="formdata.office.address" ng-required="formdata.role == 'therapist_nooffice'"/> <input type="text" class="form-control" placeholder="{{ 'address' | translate }}" ng-model="formdata.office.address" ng-required="formdata.role == 'therapist_nooffice'"/>
...@@ -195,24 +197,15 @@ ...@@ -195,24 +197,15 @@
<div class="row"> <div class="row">
<div class="col-md-6"> <div class="col-md-6">
<div class="form-group"> <div class="form-group">
<input type="number" class="form-control" placeholder="{{ 'postal_code' | translate }}" ng-model="formdata.office.postal_code" ng-change="formdata.office.postal_code = formdata.office.postal_code.toUpperCase()" ng-required="formdata.role == 'therapist_nooffice'"/> <input type="text" class="form-control" placeholder="{{ 'postal_code' | translate }}" ng-model="formdata.office.postalCode" ng-change="formdata.office.postalCode = formdata.office.postalCode.toUpperCase()" ng-required="formdata.role == 'therapist_nooffice'"/>
</div> </div>
</div> </div>
<div class="col-md-6"> <div class="col-md-6">
<div class="form-group"> <div class="form-group">
<select class="form-control" ng-model="formdata.office.country" ng-required="formdata.role == 'therapist_nooffice'"> <input type="text" class="form-control" placeholder="{{ 'contact_person' | translate }}" ng-model="formdata.office.contactPerson" ng-required="formdata.role == 'therapist_nooffice'"/>
<option value="00" selected disabled hidden>{{ 'country' | translate }}</option>
<option value="ES">España</option>
<option value="US">United States</option>
<option value="UK">United Kingdom</option>
<option value="IE">Ireland</option>
</select>
</div> </div>
</div> </div>
</div> </div>
<div class="form-group">
<input type="text" class="form-control" placeholder="{{ 'contact_person' | translate }}" ng-model="formdata.office.contact_person" ng-required="formdata.role == 'therapist_nooffice'"/>
</div>
<div class="row"> <div class="row">
<div class="col-md-6"> <div class="col-md-6">
<div class="form-group"> <div class="form-group">
......
...@@ -5,31 +5,19 @@ ...@@ -5,31 +5,19 @@
//-------------------------- //--------------------------
dashboardControllers.controller('SupervisorsCtrl', function SupervisorsCtrl($scope, $window, $http, config, $translate, ngToast) { dashboardControllers.controller('SupervisorsCtrl', function SupervisorsCtrl($scope, $window, $http, config, $translate, ngToast) {
//Office ID // Restore user data from session
var user = JSON.parse($window.sessionStorage.user);
$http $http
.get(config.backend+'/office/get_all') .get(config.backend+'/office/get/' + user.office.id + '/supervisors')
.success(function(data, status, headers, config) { .success(function(data, status, headers, config) {
// Add to list $scope.supervisors_list = data;
$scope.office = data[0]; console.log($scope.supervisors_list);
$scope.supervisors_list();
}) })
.error(function(data, status, headers, config) { .error(function(data, status, headers, config) {
console.log("Error from API: " + data.error); $translate('error_downloading_supervisors').then(function (translation) {
ngToast.danger({ content: translation });
});
}); });
// List of supervisors
$scope.supervisors_list = function(){
$http
.get(config.backend+'/office/get/' + $scope.office.id + '/supervisors')
.success(function(data, status, headers, config) {
$scope.supervisors_list = data;
console.log($scope.supervisors_list);
})
.error(function(data, status, headers, config) {
$translate('error_downloading_supervisors').then(function (translation) {
ngToast.danger({ content: translation });
});
});
};
}); });
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
href="/app/#/students"> href="/app/#/students">
<img <img
class="topbar__logo__image" class="topbar__logo__image"
ng-src="{{user.office.logo_url}}" ng-src="{{user.office.logoUrl}}"
alt="{{user.office.name}}" alt="{{user.office.name}}"
title="{{user.office.name}}" /> title="{{user.office.name}}" />
</a> </a>
......
...@@ -4,8 +4,9 @@ ...@@ -4,8 +4,9 @@
"notification_from_pictogram": "Notification from Pictogram", "notification_from_pictogram": "Notification from Pictogram",
"signin_mail": "To activate your Pictogram account, click on this link:\n", "signin_mail": "To activate your Pictogram account, click on this link:\n",
"change_password_mail": "To change your password, please click on the following link:\n", "change_password_mail": "To change your password, please click on the following link:\n",
"login": "login",
"therapist_office_request": "{{ name }}, with email {{ email }}, is requesting to be linked as therapist to any of your students.", "therapist_office_request": "{{ name }}, with email {{ email }}, is requesting to be linked as therapist to any of your students.",
"tutor_office_request": "{{ name }}, with email {{ email }}, is requesting to be linked as tutor/father/mother to any of your students.", "tutor_office_request": "{{ name }}, with email {{ email }}, is requesting to be linked as tutor/father/mother to any of your students.",
"welcome_msg1": "Welcome to Pictogram, {{ name }}!", "welcome_msg1": "Welcome to Pictogram, {{ name }}!",
"welcome_msg2": "Your account is now active. You can proceed to <a href=\"{{ login_url }}\">login</a>." "welcome_msg2": "Your account is now active. You can proceed to"
} }
...@@ -8,5 +8,5 @@ ...@@ -8,5 +8,5 @@
"therapist_office_request {{ name }} {{ email }}": "El terapeuta {{ name }}, con correo electrónico {{ email }}, pide ser asociado a algún estudiante.", "therapist_office_request {{ name }} {{ email }}": "El terapeuta {{ name }}, con correo electrónico {{ email }}, pide ser asociado a algún estudiante.",
"tutor_office_request {{ name }} {{ email }}": "El tutor {{ name }}, con correo electrónico {{ email }}, pide ser asociado a algún estudiante.", "tutor_office_request {{ name }} {{ email }}": "El tutor {{ name }}, con correo electrónico {{ email }}, pide ser asociado a algún estudiante.",
"welcome_msg1": "¡Bienvenido a Pictogram, {{ name }}!", "welcome_msg1": "¡Bienvenido a Pictogram, {{ name }}!",
"welcome_msg2": "Su cuenta está ahora activa, por lo que puede <a href=\"{{ login_url }}\">acceder</a>." "welcome_msg2": "Su cuenta está ahora activa, por lo que puede"
} }
...@@ -8,10 +8,25 @@ ...@@ -8,10 +8,25 @@
</head> </head>
<body> <body>
<img title="Pictogram" alt="Pictogram" src="/app/img/logo_pictogram.png"> <div class="container">
<div class="row">
<div class="col-md-2">
<img title="Pictogram" alt="Pictogram" src="/app/img/logo_pictogram.png" style="margin-top:40px">
</div>
<div class="col-md-10">
<div class="page-header">
<h1><%= welcome_msg1 %></h1>
</div>
<p class="lead"><%= welcome_msg2 %> <a href="<%= login_url %>"><%= login %></a>.</p>
</div>
</div>
</div>
<p><strong>{{ welcome_msg1 }}</strong></p> <footer class="footer">
<p>{{ welcome_msg2 }}</p> <div class="container">
<p class="text-muted">Pictogram Web - Yottacode S.L.</p>
</div>
</footer>
</body> </body>
</html> </html>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment