1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-11 22:24:21 +01:00
fab-manager/app/assets/javascripts/controllers/dashboard.js

52 lines
1.5 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', 'SocialNetworks', function ($scope, memberPromise, 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
/* 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
/**
* Filter social network or website that are associated with the profile of the user provided in promise
* and return the filtered networks
* @return {Array}
*/
var filterNetworks = function () {
2018-11-21 11:08:53 +01:00
const networks = [];
for (let 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
// !!! 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
]);