2018-10-25 16:51:20 +02:00
|
|
|
/* eslint-disable
|
|
|
|
no-return-assign,
|
|
|
|
no-undef,
|
|
|
|
*/
|
|
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
|
|
// Fix any style issues and re-enable lint.
|
2018-10-25 16:50:16 +02:00
|
|
|
/*
|
|
|
|
* decaffeinate suggestions:
|
|
|
|
* DS101: Remove unnecessary use of Array.from
|
|
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
|
*/
|
2018-11-21 11:08:53 +01:00
|
|
|
'use strict';
|
2018-10-25 16:50:16 +02:00
|
|
|
|
2021-03-08 15:17:58 +01:00
|
|
|
Application.Controllers.controller('DashboardController', ['$scope', 'memberPromise', 'trainingsPromise', 'SocialNetworks', function ($scope, memberPromise, trainingsPromise, SocialNetworks) {
|
2018-11-21 09:42:26 +01:00
|
|
|
// Current user's profile
|
2018-11-21 11:08:53 +01:00
|
|
|
$scope.user = memberPromise;
|
2018-10-25 16:50:16 +02:00
|
|
|
|
2018-11-21 09:42:26 +01:00
|
|
|
// List of social networks associated with this user and toggle 'show all' state
|
2018-10-25 16:50:16 +02:00
|
|
|
$scope.social = {
|
|
|
|
showAllLinks: false,
|
2016-05-17 16:41:32 +02:00
|
|
|
networks: SocialNetworks
|
2018-11-21 11:08:53 +01:00
|
|
|
};
|
2016-05-17 16:41:32 +02:00
|
|
|
|
2021-03-08 15:17:58 +01:00
|
|
|
/**
|
|
|
|
* Check if the member has used his training credits for the given credit
|
|
|
|
* @param trainingCredits array of credits used by the member
|
|
|
|
* @param trainingId id of the training to find
|
|
|
|
*/
|
|
|
|
$scope.hasUsedTrainingCredit = function (trainingCredits, trainingId) {
|
|
|
|
return trainingCredits.find(tc => tc.training_id === trainingId);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the name associated with the provided training ID
|
|
|
|
* @param trainingId training identifier
|
|
|
|
* @return {string}
|
|
|
|
*/
|
|
|
|
$scope.getTrainingName = function (trainingId) {
|
|
|
|
return trainingsPromise.find(t => t.id === trainingId).name;
|
|
|
|
};
|
|
|
|
|
2018-10-25 16:50:16 +02:00
|
|
|
/* PRIVATE SCOPE */
|
2016-05-17 16:41:32 +02:00
|
|
|
|
2018-11-21 09:42:26 +01:00
|
|
|
/**
|
|
|
|
* Kind of constructor: these actions will be realized first when the controller is loaded
|
|
|
|
*/
|
2018-11-21 11:08:53 +01:00
|
|
|
const initialize = () => $scope.social.networks = filterNetworks();
|
2016-05-17 16:41:32 +02:00
|
|
|
|
2018-11-21 09:42:26 +01:00
|
|
|
/**
|
2021-02-09 17:18:33 +01:00
|
|
|
* Filter the social networks or websites that are associated with the profile of the user provided in promise
|
2018-11-21 09:42:26 +01:00
|
|
|
* and return the filtered networks
|
|
|
|
* @return {Array}
|
|
|
|
*/
|
2021-02-09 17:18:33 +01:00
|
|
|
const filterNetworks = function () {
|
2018-11-21 11:08:53 +01:00
|
|
|
const networks = [];
|
2021-02-09 17:18:33 +01:00
|
|
|
for (const network of Array.from(SocialNetworks)) {
|
2018-10-25 16:50:16 +02:00
|
|
|
if ($scope.user.profile[network] && ($scope.user.profile[network].length > 0)) {
|
2018-11-21 11:08:53 +01:00
|
|
|
networks.push(network);
|
2018-10-25 16:50:16 +02:00
|
|
|
}
|
|
|
|
}
|
2018-11-21 11:08:53 +01:00
|
|
|
return networks;
|
|
|
|
};
|
2016-05-17 16:41:32 +02:00
|
|
|
|
2021-06-04 18:26:20 +02:00
|
|
|
/**
|
|
|
|
* Callback used in PaymentScheduleDashboard, in case of error
|
|
|
|
*/
|
|
|
|
$scope.onError = function (message) {
|
|
|
|
growl.error(message);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback triggered when the user has successfully updated his card
|
|
|
|
*/
|
|
|
|
$scope.onCardUpdateSuccess = function (message) {
|
|
|
|
growl.success(message);
|
|
|
|
};
|
|
|
|
|
2018-11-21 09:42:26 +01:00
|
|
|
// !!! MUST BE CALLED AT THE END of the controller
|
2018-11-21 11:08:53 +01:00
|
|
|
return initialize();
|
2018-10-25 16:50:16 +02:00
|
|
|
}
|
2016-05-17 16:41:32 +02:00
|
|
|
|
2018-11-21 11:08:53 +01:00
|
|
|
]);
|