1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-11-29 10:24:20 +01:00
fab-manager/app/assets/javascripts/controllers/home.coffee

55 lines
1.9 KiB
CoffeeScript
Raw Normal View History

2015-05-05 03:10:25 +02:00
'use strict'
2016-03-23 18:39:41 +01:00
Application.Controllers.controller "HomeController", ['$scope', '$stateParams', 'Twitter', 'lastMembersPromise', 'lastProjectsPromise', 'upcomingEventsPromise', 'homeBlogpostPromise', 'twitterNamePromise', ($scope, $stateParams, Twitter, lastMembersPromise, lastProjectsPromise, upcomingEventsPromise, homeBlogpostPromise, twitterNamePromise)->
2015-05-05 03:10:25 +02:00
### PUBLIC SCOPE ###
## The last registered members who confirmed their addresses
2016-03-23 18:39:41 +01:00
$scope.lastMembers = lastMembersPromise
2015-05-05 03:10:25 +02:00
## The last tweets from the Fablab official twitter account
2016-03-23 18:39:41 +01:00
$scope.lastTweets = []
2015-05-05 03:10:25 +02:00
## The last projects published/documented on the plateform
2016-03-23 18:39:41 +01:00
$scope.lastProjects = lastProjectsPromise
2015-05-05 03:10:25 +02:00
## The closest upcoming events
2016-03-23 18:39:41 +01:00
$scope.upcomingEvents = upcomingEventsPromise
## The admin blogpost
$scope.homeBlogpost = homeBlogpostPromise.setting.value
## Twitter username
$scope.twitterName = twitterNamePromise.setting.value
##
# Test if the provided event run on a single day or not
# @param event {Object} single event from the $scope.upcomingEvents array
# @returns {boolean} false if the event runs on more that 1 day
##
$scope.isOneDayEvent = (event) ->
moment(event.start_date).isSame(event.end_date, 'day')
2015-05-05 03:10:25 +02:00
### PRIVATE SCOPE ###
##
# Kind of constructor: these actions will be realized first when the controller is loaded
##
initialize = ->
2016-03-23 18:39:41 +01:00
# we retrieve tweets from here instead of ui-router's promise because, if adblock stop the API request,
# this prevent the whole home page to be blocked
$scope.lastTweets = Twitter.query(limit: 1)
# if we recieve a token to reset the password as GET parameter, trigger the
# changePassword modal from the parent controller
2015-05-05 03:10:25 +02:00
if $stateParams.reset_password_token
$scope.$parent.editPassword($stateParams.reset_password_token)
## !!! MUST BE CALLED AT THE END of the controller
initialize()
]