1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-08 23:46:14 +01:00
fab-manager/app/frontend/src/javascript/controllers/dashboard.js

84 lines
2.4 KiB
JavaScript
Raw Normal View History

/* eslint-disable
no-return-assign,
no-undef,
*/
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
/*
* 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';
Application.Controllers.controller('DashboardController', ['$scope', 'memberPromise', 'trainingsPromise', 'SocialNetworks', function ($scope, memberPromise, trainingsPromise, SocialNetworks) {
// Current user's profile
2018-11-21 11:08:53 +01:00
$scope.user = memberPromise;
// List of social networks associated with this user and toggle 'show all' state
$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
/**
* 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;
};
/* PRIVATE SCOPE */
2016-05-17 16:41:32 +02: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
/**
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
* 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)) {
if ($scope.user.profile[network] && ($scope.user.profile[network].length > 0)) {
2018-11-21 11:08:53 +01:00
networks.push(network);
}
}
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);
};
// !!! MUST BE CALLED AT THE END of the controller
2018-11-21 11:08:53 +01:00
return initialize();
}
2016-05-17 16:41:32 +02:00
2018-11-21 11:08:53 +01:00
]);