forked from code-dot-org/code-dot-org
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathangularProjects.js
More file actions
83 lines (68 loc) · 2.46 KB
/
Copy pathangularProjects.js
File metadata and controls
83 lines (68 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/* global angular */
'use strict';
// Declare app level module which depends on filters, and services
angular.module('projectsApp', [
'ngRoute',
'ngResource',
'projectsApp.controllers',
'projectsApp.services'
]).config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/',
{templateUrl: '/projects/angular', controller: 'ProjectsController'});
$routeProvider.otherwise({redirectTo: '/'});
}]);
// SERVICES
var services = angular.module('projectsApp.services', []).
value('version', '0.1');
// Section service. see sites.v3/code.org/routes/v2_section_routes.rb
services.factory('projectsService', ['$resource',
function($resource) {
var Project = $resource('/v3/channels/:id', {}, {
// default methods: see https://code.angularjs.org/1.2.21/docs/api/ngResource/service/$resource
// 'get': {method: 'GET'},
// 'save': {method: 'POST'},
// 'query': {method: 'GET', isArray:true},
// 'remove': {method: 'DELETE'},
// 'delete': {method: 'DELETE'} // don't use this because it doesn't work in IE9
});
Project.prototype.url = function() {
if (this.level && this.id) {
return this.level.replace(/\/p\//, '/projects/') + '/' + this.id;
} else {
return null;
}
};
Project.prototype.editUrl = function() {
if (this.url()) {
return this.url() + "/edit";
} else {
return null;
}
};
return Project;
}]);
// CONTROLLERS
var controllers = angular.module('projectsApp.controllers', []).
value('version', '0.1');
controllers.controller('ProjectsController', ['$scope', '$route', '$routeParams', '$location', '$window', 'projectsService',
function($scope, $route, $routeParams, $location, $window, projectsService) {
$scope.projectsLoaded = false;
$scope.projects = projectsService.query();
// set initial sort order
$scope.order = 'updatedAt';
$scope.reverse = true;
$scope.projects.$promise.then(function(projects) {
$scope.projectsLoaded = true;
}).catch($scope.genericError);
$scope.projectVisible = function(project) {
return (!project.hidden);
};
$scope.genericError = function(result) {
$window.alert("An unexpected error occurred, please try again. If this keeps happening, try reloading the page.");
};
$scope.removeProject = function (project) {
project.$remove({id: project.id}, function() {
$scope.projects.splice($.inArray(project, $scope.projects), 1);
});
};
}]);