Advertisement
Guest User

link

a guest
Oct 30th, 2013
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.80 KB | None | 0 0
  1. 'use strict';
  2.  
  3. moment.lang('en');
  4.  
  5. angular.module('Wagnaria', ['ui.router', 'ngResource', 'piwik'])
  6. .run([
  7. '$rootScope', '$state', '$stateParams',
  8. function ($rootScope, $state, $stateParams) {
  9. $rootScope.$state = $state;
  10. $rootScope.$stateParams = $stateParams;
  11. console.log('running');
  12. }])
  13. .factory('Shows', ['$resource',
  14. function($resource) {
  15. return $resource( '/api/1/shows/:showId.json', {showId: '@_id.$oid'}, {
  16. 'getAiring': { method: 'GET', url: '/api/1/shows/airing.json', isArray: true },
  17. 'getCompleted': { method: 'GET', url: '/api/1/shows/completed.json', isArray: true },
  18. 'getIncomplete': { method: 'GET', url: '/api/1/shows/incomplete.json', isArray: true },
  19. 'getUnaired': { method: 'GET', url: '/api/1/shows/unaired.json', isArray: true }
  20. });
  21. }])
  22. .factory('staff', ['$resource',
  23. function($resource) {
  24. return $resource( '/api/1/staff/:memberId.json', {memberId: '@_id.$oid'} );
  25. }]);
  26.  
  27. angular.module('Wagnaria')
  28. .controller('ShowsCtrl', ['$scope', '$state', '$stateParams', 'Shows', 'Piwik',
  29. function($scope, $state, $stateParams, Shows, Piwik) {
  30. console.log('loading shows');
  31. if($stateParams.showId) {
  32. $scope.show = Shows;
  33. Piwik.setDocumentTitle($scope.show.titles.english);
  34. Piwik.setCustomUrl(location.href.replace(location.hash,"") + "#/shows/" + $stateParams.showId);
  35. } else {
  36. $scope.shows = Shows;
  37. var p_titles = {
  38. "shows.incomplete": "Incomplete Shows",
  39. "shows.complete": "Completed Shows",
  40. "shows.airing": "Airing Shows",
  41. "shows.unaired": "Future Shows"
  42. };
  43. console.log($state);
  44. Piwik.setDocumentTitle(p_titles[$state.current.name]);
  45. Piwik.setCustomUrl(location.href.replace(location.hash,"") + "#" + $state.$current.url.source);
  46. }
  47. $scope.localise_date = function(date) {
  48. return moment(date).format('llll');
  49. };
  50. $scope.nipify_date = function(date) {
  51. return moment(date).utc().lang('ja').add('hours', +9).format('llll');
  52. }
  53. $scope.setSort = function(newSort) {
  54. this.reverse = this.sorted == newSort ? !this.reverse : false;
  55. this.sorted = newSort;
  56. }
  57. }
  58. ])
  59. .controller('StatusCtrl', ['$scope', '$http',
  60. function($scope, $http) {
  61. var loadCounts = function() {
  62. $http({method: 'GET', url: '/api/1/shows/status.json'})
  63. .success(function (data) {
  64. $scope.counts = data;
  65. })
  66. .error(function(data, status) {
  67. console.log(status + data);
  68. });
  69. }
  70. loadCounts();
  71. }
  72. ]);
  73.  
  74. angular.module('Wagnaria')
  75. .config([
  76. '$stateProvider', '$urlRouterProvider',
  77. function($stateProvider, $urlRouterProvider) {
  78. $urlRouterProvider
  79. .when('/', '/shows/airing')
  80. .otherwise('/shows/airing');
  81. $stateProvider
  82. .state('shows', {
  83. url: '/shows',
  84. abstract: true,
  85. template: '<div id="muffinbox" data-ui-view></div>',
  86. })
  87. .state('shows.detail', {
  88. url: '/{showId:[0-9a-f]{24}}',
  89. templateUrl: 'tpl/shows.detail.html',
  90. resolve: {
  91. Shows: ['Shows', '$stateParams', function(Shows, $stateParams){ return Shows.get({showId: $stateParams.showId}).$promise; }]
  92. },
  93. controller: 'ShowsCtrl'
  94. })
  95. .state('shows.complete', {
  96. url: '/completed',
  97. templateUrl: 'tpl/completed.html',
  98. resolve: {
  99. Shows: ['Shows',
  100. function(Shows){ return Shows.getCompleted().$promise; }
  101. ]
  102. },
  103. controller: 'ShowsCtrl'
  104. })
  105. .state('shows.incomplete', {
  106. url: '/incomplete',
  107. templateUrl: 'tpl/airing.html',
  108. resolve: {
  109. Shows: ['Shows',
  110. function(Shows){ return Shows.getIncomplete().$promise; }
  111. ]
  112. },
  113. controller: 'ShowsCtrl'
  114. })
  115. .state('shows.unaired', {
  116. url: '/unaired',
  117. templateUrl: 'tpl/completed.html',
  118. resolve: {
  119. Shows: ['Shows',
  120. function(Shows){ return Shows.getUnaired().$promise; }
  121. ]
  122. },
  123. controller: 'ShowsCtrl'
  124. })
  125. .state('shows.airing', {
  126. url: '/airing',
  127. templateUrl: 'tpl/airing.html',
  128. resolve: {
  129. Shows: ['Shows',
  130. function(Shows){ return Shows.getAiring().$promise; }
  131. ]
  132. },
  133. controller: 'ShowsCtrl'
  134. });
  135. }
  136. ]);
  137.  
  138. angular.module('Wagnaria')
  139. .directive('memberHighlight', function() {
  140. return {
  141. restrict: 'A',
  142. scope: { memberName: '@', progress: '@', status: '@' },
  143. template: '{{memberName}}',
  144. link: function(scope, elm, attrs) {
  145. if(scope.status == 'airing' || scope.status == 'incomplete'){
  146. elm.addClass('staff-status-' + scope.progress);
  147. }
  148. }
  149. }
  150. })
  151. .directive('eta', function($timeout) {
  152. return {
  153. scope: { airtime: '=eta' },
  154. template: '{{eta}}',
  155. link: function postLink(scope, elm, attrs) {
  156. var timeoutId, eta, eta_min;
  157. function updateETA() {
  158. var now = moment();
  159. var air = moment(scope.airtime);
  160. eta = air.from(now);
  161. elm.text(eta);
  162. eta_min = air.diff(now, 'minutes');
  163. if(eta_min < -30) { elm.parent().removeClass('airing_1'); elm.parent().addClass('subbing'); }
  164. if(eta_min > 0 && eta_min <= 60) { elm.parent().removeClass('airing_3'); elm.parent().addClass('airing_1'); }
  165. if(eta_min > 60 && eta_min <= 180) { elm.parent().removeClass('airing_6'); elm.parent().addClass('airing_3'); }
  166. if(eta_min > 180 && eta_min <= 360) { elm.parent().removeClass('airing_12'); elm.parent().addClass('airing_6'); }
  167. if(eta_min > 360 && eta_min <= 720) { elm.parent().addClass('airing_12'); }
  168. }
  169. function timer(nextminute) {
  170. timeoutId = $timeout(function() {
  171. updateETA();
  172. timer(60000);
  173. }, nextminute);
  174. }
  175. function secondsTilNextMinute() {
  176. var current_second = moment().second();
  177. return 60 - current_second;
  178. }
  179. elm.on('$destroy', function() { $timeout.cancel(timeoutId); });
  180. updateETA();
  181. timer(secondsTilNextMinute*1000);
  182. }
  183. }
  184. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement