show only your office's supervisors

parent 054e9e17
......@@ -13,3 +13,5 @@ Database
`alter table supervisor add column `postal_code` char(10) COLLATE utf8_unicode_ci NOT NULL;`
- 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;`
- alter table office
`alter table office modify logo_url varchar(240) default null;`
......@@ -100,7 +100,7 @@ module.exports = {
}
if (!supervisor.isSupAdmin && !stuSup)
throw res.unauthorized("Supervisor without students");
return res.unauthorized("Supervisor without students");
return res.ok({
user: supervisor,
......@@ -108,7 +108,6 @@ module.exports = {
token: sailsTokenAuth.issueToken(supervisor, sails.config.jwt.expiresInMinutes)
});
})
.catch(function (err) {
return res.serverError("Error when connecting to database");
});
......@@ -186,7 +185,9 @@ module.exports = {
welcome_msg2: sails.__({
phrase: 'welcome_msg2',
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 = {
// Send email confirmation
function sendConfirmationMail(cb) {
console.log("mail------------\n" + JSON.stringify(supervisor));
var token = sailsTokenAuth.issueToken({
id_sup: supervisor.id,
role: params.role,
......@@ -283,15 +286,14 @@ module.exports = {
})
.then(() => {cb();})
.catch((err) => {cb(err);});
}
} // /sendConfirmationEmail()
sails.log.debug("Creating supervisor with params " + JSON.stringify(params));
if (!params.name || !params.surname || !params.gender || !params.password || !params.email )
res.badRequest("Invalid params");
Supervisor.create({
var supData = {
name: params.name,
surname: params.surname,
gender: params.gender,
......@@ -299,13 +301,17 @@ module.exports = {
email: params.email,
pic: sails.config.pictogram.paths.defaultAvatarFileName,
address: params.address || '',
postal_code: params.postal_code || '',
country: params.country || null,
postalCode: params.postalCode || '',
country: params.country || '',
phone: params.phone || '',
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) {
if (!sup)
......@@ -319,11 +325,19 @@ module.exports = {
return res.ok();
});
} else if (params.role === 'therapist_nooffice' || params.role === 'tutor_nooffice') {
Office.create(params.office)
.then((off) => {
// link supervisor with office
supervisor.id_off = off.id;
delete supervisor.password;
supervisor.save();
// set supervisor as admin in the office
off.admin = supervisor.id;
off.save();
sendConfirmationMail((err) => {
if (err) throw err;
return res.ok();
......
......@@ -26,15 +26,25 @@ module.exports = {
type: "string",
size: 80
},
logoUrl: {
columnName: 'logo_url',
type: "string",
size: 240
},
address: {
required: true,
type: "string",
size: 80
},
logo_url: {
country: {
type: "string",
size: 5,
required: true
},
lang: {
required: true,
type: "string",
size: 240
size: 2
},
contactPerson: {
columnName: "contact_person",
......@@ -57,29 +67,17 @@ module.exports = {
type: "string",
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: {
columnName: 'admin',
required: true,
type: 'integer',
model: 'Supervisor'
},
postalCode: {
columnName: 'postal_code',
required: true,
type: "string",
size: 10
},
// Relación con Teacher. [1 Office to N Teacher]
supervisors: {
collection: "Supervisor",
......@@ -90,5 +88,12 @@ module.exports = {
collection: "Student",
via: 'office'
}
},
beforeCreate: function (attrs, next) {
if (attrs.logoUrl)
attrs.logoUrl = '/app/img/logo_pictogram.png';
next();
}
};
......@@ -52,7 +52,8 @@ module.exports = {
type: "string",
size: 180
},
postal_code: {
postalCode: {
columnName: 'postal_code',
type: "string",
size: 10
},
......
......@@ -24,7 +24,7 @@ function LoginCtrl(
};
$scope.office = {
logo_url : 'img/logo_pictogram.png',
logoUrl : 'img/logo_pictogram.png',
name : 'Pictogram'
};
......@@ -48,8 +48,8 @@ function LoginCtrl(
data.user.isTutor = true;
} else
data.user.isTutor = false;
if (data.user.office.logo_url.length < 5)
data.user.office.logo_url = 'img/logo_pictogram.png';
if (data.user.office.logoUrl.length < 5)
data.user.office.logoUrl = 'img/logo_pictogram.png';
$window.sessionStorage.token = data.token;
......
......@@ -34,11 +34,12 @@ function SignInCtrl($scope,
office: {
name: '',
address: '',
postal_code: '',
postalCode: '',
country: '00',
contact_person: '',
phone: '',
email: ''
contactPerson: '',
phone1: '',
email: '',
logoUrl: ''
},
office_idx: -1
};
......@@ -56,6 +57,17 @@ function SignInCtrl($scope,
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
$scope.signin = function () {
// Validate email match
......@@ -108,11 +120,12 @@ function SignInCtrl($scope,
if ($scope.formdata.role === 'tutor_nooffice') {
$scope.formdata.office.name = $scope.formdata.name + " " + $scope.formdata.surname;
$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.contact_person = $scope.formdata.name + " " + $scope.formdata.surname;
$scope.formdata.office.phone = $scope.formdata.phone;
$scope.formdata.office.contactPerson = $scope.formdata.name + " " + $scope.formdata.surname;
$scope.formdata.office.phone1 = $scope.formdata.phone;
$scope.formdata.office.email = $scope.formdata.email;
$scope.formdata.office.lang = $scope.formdata.lang;
}
$http
......
......@@ -11,7 +11,7 @@
</p>
-->
<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>
<!-- Formulario -->
<!-- LoginCtrl controls here, see app.js -->
......
......@@ -38,7 +38,7 @@
<div class="row">
<div class="col-md-4">
<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 class="col-md-8">
......@@ -142,7 +142,8 @@
type="radio"
ng-model="formdata.role"
value="therapist_nooffice"
onClick="$('#office_selection').slideUp(); $('#office_form').slideDown();">
onClick="$('#office_selection').slideUp(); $('#office_form').slideDown();"
ng-click="copyFields();">
</div>
<div class="col-md-11">
{{ 'case_therapist_nooffice' | translate }}
......@@ -172,7 +173,8 @@
type="radio"
ng-model="formdata.role"
value="tutor_nooffice"
onClick="$('#office_selection').slideUp(); $('#office_form').slideUp();">
onClick="$('#office_selection').slideUp(); $('#office_form').slideUp(); copyFields();"
ng-click="copyFields();">
</div>
<div class="col-md-11">
{{ 'case_tutor_nooffice' | translate }}
......@@ -187,7 +189,7 @@
<input type="text" class="form-control" placeholder="{{ 'name' | translate }}" ng-model="formdata.office.name" ng-required="formdata.role == 'therapist_nooffice'"/>
</div>
<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 class="form-group">
<input type="text" class="form-control" placeholder="{{ 'address' | translate }}" ng-model="formdata.office.address" ng-required="formdata.role == 'therapist_nooffice'"/>
......@@ -195,24 +197,15 @@
<div class="row">
<div class="col-md-6">
<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 class="col-md-6">
<div class="form-group">
<select class="form-control" ng-model="formdata.office.country" 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>
<input type="text" class="form-control" placeholder="{{ 'contact_person' | translate }}" ng-model="formdata.office.contactPerson" ng-required="formdata.role == 'therapist_nooffice'"/>
</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="col-md-6">
<div class="form-group">
......
......@@ -5,22 +5,11 @@
//--------------------------
dashboardControllers.controller('SupervisorsCtrl', function SupervisorsCtrl($scope, $window, $http, config, $translate, ngToast) {
//Office ID
$http
.get(config.backend+'/office/get_all')
.success(function(data, status, headers, config) {
// Add to list
$scope.office = data[0];
$scope.supervisors_list();
})
.error(function(data, status, headers, config) {
console.log("Error from API: " + data.error);
});
// Restore user data from session
var user = JSON.parse($window.sessionStorage.user);
// List of supervisors
$scope.supervisors_list = function(){
$http
.get(config.backend+'/office/get/' + $scope.office.id + '/supervisors')
.get(config.backend+'/office/get/' + user.office.id + '/supervisors')
.success(function(data, status, headers, config) {
$scope.supervisors_list = data;
console.log($scope.supervisors_list);
......@@ -30,6 +19,5 @@ dashboardControllers.controller('SupervisorsCtrl', function SupervisorsCtrl($sco
ngToast.danger({ content: translation });
});
});
};
});
......@@ -8,7 +8,7 @@
href="/app/#/students">
<img
class="topbar__logo__image"
ng-src="{{user.office.logo_url}}"
ng-src="{{user.office.logoUrl}}"
alt="{{user.office.name}}"
title="{{user.office.name}}" />
</a>
......
......@@ -4,8 +4,9 @@
"notification_from_pictogram": "Notification from Pictogram",
"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",
"login": "login",
"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.",
"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 @@
"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.",
"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 @@
</head>
<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>
<p>{{ welcome_msg2 }}</p>
<footer class="footer">
<div class="container">
<p class="text-muted">Pictogram Web - Yottacode S.L.</p>
</div>
</footer>
</body>
</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