Skip to content

Commit 584f685

Browse files
authored
Merge pull request code-dot-org#26967 from code-dot-org/prettify-shared-js
prettify shared/*.js, since apparently these are linted, too
2 parents 4196646 + 8673c1e commit 584f685

File tree

2 files changed

+140
-102
lines changed

2 files changed

+140
-102
lines changed

shared/js/angularProjects.js

Lines changed: 134 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -1,142 +1,177 @@
11
/* global $, angular */
2-
var script = document.querySelector('script[data-under13]');
2+
var script = document.querySelector("script[data-under13]");
33
var userSharingDisabled = JSON.parse(script.dataset.sharingdisabled);
44

55
// Declare app level module which depends on filters, and services
6-
angular.module('projectsApp', [
7-
'ngRoute',
8-
'ngResource',
9-
'projectsApp.controllers',
10-
'projectsApp.services'
11-
]).config(['$routeProvider', function ($routeProvider) {
12-
$routeProvider.when('/',
13-
{templateUrl: '/projects/angular', controller: 'ProjectsController'});
14-
$routeProvider.otherwise({redirectTo: '/'});
15-
}]);
6+
angular
7+
.module("projectsApp", [
8+
"ngRoute",
9+
"ngResource",
10+
"projectsApp.controllers",
11+
"projectsApp.services"
12+
])
13+
.config([
14+
"$routeProvider",
15+
function($routeProvider) {
16+
$routeProvider.when("/", {
17+
templateUrl: "/projects/angular",
18+
controller: "ProjectsController"
19+
});
20+
$routeProvider.otherwise({ redirectTo: "/" });
21+
}
22+
]);
1623

1724
// SERVICES
18-
var services = angular.module('projectsApp.services', [])
19-
.value('version', '0.1');
25+
var services = angular
26+
.module("projectsApp.services", [])
27+
.value("version", "0.1");
2028

2129
// Section service. see sites.v3/code.org/routes/v2_section_routes.rb
22-
services.factory('projectsService', ['$resource',
23-
function ($resource) {
24-
var Project = $resource('/v3/channels/:id', {}, {
25-
// default methods: see https://code.angularjs.org/1.2.21/docs/api/ngResource/service/$resource
26-
// 'get': {method: 'GET'},
27-
// 'save': {method: 'POST'},
28-
// 'query': {method: 'GET', isArray:true},
29-
// 'remove': {method: 'DELETE'},
30-
// 'delete': {method: 'DELETE'} // don't use this because it doesn't work in IE9
31-
});
32-
33-
Project.prototype.url = function () {
30+
services.factory("projectsService", [
31+
"$resource",
32+
function($resource) {
33+
var Project = $resource(
34+
"/v3/channels/:id",
35+
{},
36+
{
37+
// default methods: see https://code.angularjs.org/1.2.21/docs/api/ngResource/service/$resource
38+
// 'get': {method: 'GET'},
39+
// 'save': {method: 'POST'},
40+
// 'query': {method: 'GET', isArray:true},
41+
// 'remove': {method: 'DELETE'},
42+
// 'delete': {method: 'DELETE'} // don't use this because it doesn't work in IE9
43+
}
44+
);
45+
46+
Project.prototype.url = function() {
3447
if (this.level && this.id) {
35-
return this.level.replace(/\/p\//, '/projects/') + '/' + this.id;
48+
return this.level.replace(/\/p\//, "/projects/") + "/" + this.id;
3649
} else {
3750
return null;
3851
}
3952
};
4053

41-
Project.prototype.editUrl = function () {
54+
Project.prototype.editUrl = function() {
4255
if (this.url()) {
4356
return this.url() + "/edit";
4457
} else {
4558
return null;
4659
}
4760
};
4861

49-
Project.prototype.thumbnail = function () {
62+
Project.prototype.thumbnail = function() {
5063
if (this.thumbnailUrl) {
5164
return this.thumbnailUrl;
5265
} else {
53-
return '/blockly/media/projects/project_default.png';
66+
return "/blockly/media/projects/project_default.png";
5467
}
5568
};
5669

57-
Project.prototype.getType = function () {
70+
Project.prototype.getType = function() {
5871
// Until projectType is back-filled, check level when projectType is missing.
59-
return this.projectType ?
60-
this.projectType :
61-
this.level && this.level.substr('/projects/'.length);
72+
return this.projectType
73+
? this.projectType
74+
: this.level && this.level.substr("/projects/".length);
6275
};
6376

64-
Project.prototype.isPublishableProjectType = function () {
77+
Project.prototype.isPublishableProjectType = function() {
6578
var projectType = this.getType();
66-
var publishableTypes = userSharingDisabled ?
67-
window.AlwaysPublishableProjectTypes :
68-
window.AllPublishableProjectTypes;
79+
var publishableTypes = userSharingDisabled
80+
? window.AlwaysPublishableProjectTypes
81+
: window.AllPublishableProjectTypes;
6982
return publishableTypes.indexOf(projectType) > -1;
7083
};
7184

7285
return Project;
73-
}]);
86+
}
87+
]);
7488

7589
// CONTROLLERS
7690

77-
var controllers = angular.module('projectsApp.controllers', [])
78-
.value('version', '0.1');
79-
80-
controllers.controller('ProjectsController', ['$scope', '$http', '$route', '$routeParams', '$location', '$window', 'projectsService',
81-
function ($scope, $http, $route, $routeParams, $location, $window, projectsService) {
82-
$scope.projectsLoaded = false;
83-
84-
$scope.projects = projectsService.query();
85-
86-
// set initial sort order
87-
$scope.order = 'updatedAt';
88-
$scope.reverse = true;
89-
90-
$scope.projects.$promise.then(function (projects) {
91-
$scope.projectsLoaded = true;
92-
}).catch($scope.genericError);
93-
94-
$scope.projectVisible = function (project) {
95-
return (!project.hidden);
96-
};
97-
98-
$scope.genericError = function (result) {
99-
$window.alert("An unexpected error occurred, please try again. If this keeps happening, try reloading the page.");
100-
};
101-
102-
$scope.removeProject = function (project) {
103-
project.$remove({id: project.id}, function () {
104-
$scope.projects.splice($.inArray(project, $scope.projects), 1);
105-
});
106-
};
107-
108-
$scope.showPublishProjectDialog = function (project) {
109-
var projectType = getProjectType(project);
110-
window.onShowConfirmPublishDialog(project.id, projectType);
111-
};
112-
113-
// Make this method available to projects/index.js. This can go away
114-
// once this file is moved to React.
115-
window.setProjectPublishedAt = function (projectId, publishedAt) {
116-
for (var i = 0; i < $scope.projects.length; i++) {
117-
var project = $scope.projects[i];
118-
if (project.id === projectId) {
119-
project.publishedAt = publishedAt;
120-
break;
121-
}
122-
}
91+
var controllers = angular
92+
.module("projectsApp.controllers", [])
93+
.value("version", "0.1");
94+
95+
controllers.controller("ProjectsController", [
96+
"$scope",
97+
"$http",
98+
"$route",
99+
"$routeParams",
100+
"$location",
101+
"$window",
102+
"projectsService",
103+
function(
104+
$scope,
105+
$http,
106+
$route,
107+
$routeParams,
108+
$location,
109+
$window,
110+
projectsService
111+
) {
112+
$scope.projectsLoaded = false;
113+
114+
$scope.projects = projectsService.query();
115+
116+
// set initial sort order
117+
$scope.order = "updatedAt";
118+
$scope.reverse = true;
119+
120+
$scope.projects.$promise
121+
.then(function(projects) {
122+
$scope.projectsLoaded = true;
123+
})
124+
.catch($scope.genericError);
125+
126+
$scope.projectVisible = function(project) {
127+
return !project.hidden;
128+
};
129+
130+
$scope.genericError = function(result) {
131+
$window.alert(
132+
"An unexpected error occurred, please try again. If this keeps happening, try reloading the page."
133+
);
134+
};
123135

124-
// Refresh the UI
125-
$scope.$apply();
126-
};
127-
128-
$scope.unpublishProject = function (project) {
129-
$http({
130-
method:'POST',
131-
url: '/v3/channels/' + project.id + '/unpublish',
132-
}).then(function (response) {
133-
if (response.data) {
134-
project.publishedAt = null;
136+
$scope.removeProject = function(project) {
137+
project.$remove({ id: project.id }, function() {
138+
$scope.projects.splice($.inArray(project, $scope.projects), 1);
139+
});
140+
};
141+
142+
$scope.showPublishProjectDialog = function(project) {
143+
var projectType = getProjectType(project);
144+
window.onShowConfirmPublishDialog(project.id, projectType);
145+
};
146+
147+
// Make this method available to projects/index.js. This can go away
148+
// once this file is moved to React.
149+
window.setProjectPublishedAt = function(projectId, publishedAt) {
150+
for (var i = 0; i < $scope.projects.length; i++) {
151+
var project = $scope.projects[i];
152+
if (project.id === projectId) {
153+
project.publishedAt = publishedAt;
154+
break;
155+
}
135156
}
136-
});
137-
};
138-
}]);
157+
158+
// Refresh the UI
159+
$scope.$apply();
160+
};
161+
162+
$scope.unpublishProject = function(project) {
163+
$http({
164+
method: "POST",
165+
url: "/v3/channels/" + project.id + "/unpublish"
166+
}).then(function(response) {
167+
if (response.data) {
168+
project.publishedAt = null;
169+
}
170+
});
171+
};
172+
}
173+
]);
139174

140175
function getProjectType(project) {
141-
return project.level.split('/')[2];
176+
return project.level.split("/")[2];
142177
}

shared/js/helpers.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
/* eslint-disable no-unused-vars */
33

44
function adjustScroll(destination) {
5-
$('html, body').animate({
6-
scrollTop: $("#" + destination).offset().top
7-
}, 1000);
5+
$("html, body").animate(
6+
{
7+
scrollTop: $("#" + destination).offset().top
8+
},
9+
1000
10+
);
811
}

0 commit comments

Comments
 (0)