Skip to content

Commit b507890

Browse files
committed
Offline drilldown
1 parent 9b5816a commit b507890

1 file changed

Lines changed: 68 additions & 41 deletions

File tree

js/script.js

Lines changed: 68 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,21 @@ var app = angular.module("AdobeOpenSource", ["ngResource"]);
1010

1111
//Get Adobe Github repos & orgs
1212
app.factory("DatasAdobe", function($resource) {
13-
// return $resource("data/server.json");
14-
// return $resource("http://localhost:8000", {'8000': ':8000'});
1513
return $resource("http://ec2-54-221-78-73.compute-1.amazonaws.com:8000", {'8000': ':8000'});
1614
});
1715

16+
//Offline backup of json
17+
app.factory("DatasAdobeOffline", function($resource) {
18+
return $resource("data/server.json");
19+
});
20+
1821
//Get Feaatured for the header
1922
app.factory("FeaturedHeader", function($resource) {
2023
return $resource("data/featured.json")
2124
});
2225

2326
//TODO : Manage offline project list when errors
24-
this.GitHubCtrl = function($scope, $sce, $filter, DatasAdobe, FeaturedHeader) {
27+
this.GitHubCtrl = function($scope, $sce, $filter, DatasAdobe, DatasAdobeOffline, FeaturedHeader) {
2528

2629
//------------------------------- Init --------------------------------
2730

@@ -59,7 +62,6 @@ this.GitHubCtrl = function($scope, $sce, $filter, DatasAdobe, FeaturedHeader) {
5962
actFeaturedItem.textHeader = $sce.trustAsHtml(actFeaturedItem.textHeader.join("\n"));
6063
};
6164
};
62-
console.log($scope.featureds);
6365
});
6466

6567
$scope.changeIndexFeatured = function(i, delta) {
@@ -81,45 +83,68 @@ this.GitHubCtrl = function($scope, $sce, $filter, DatasAdobe, FeaturedHeader) {
8183
$scope.projects = [];
8284
$scope.orgs = [];
8385

84-
//Reference Orgs
8586
DatasAdobe.query(function(rep) {
8687
if (rep[0]) {
87-
$scope.projects = rep[0].repos;
88-
$scope.orgs = rep[0].orgs;
89-
$scope.langs = rep[0].langs;
90-
$scope.stats = rep[0].stats;
91-
92-
$("#searchLang").autocomplete({
93-
source: $scope.objToNamedArray($scope.langs),
94-
select: function(e, q) {
95-
$scope.$apply(function () {
96-
$("#searchLang").val('Loading...');
97-
$scope.addFilter($scope.searchLang, q.item.value);
98-
$scope.searchLangInput = "";
99-
});
100-
return false;
101-
}
102-
});
103-
104-
$("#searchOrg").autocomplete({
105-
source: $scope.objToNamedArray($scope.orgs),
106-
select: function(e, q) {
107-
$scope.$apply(function () {
108-
$("#searchOrg").val('Loading...');
109-
$scope.addFilter($scope.searchOrg, q.item.value);
110-
$scope.searchOrgInput = "";
111-
});
112-
return false;
113-
}
114-
});
115-
116-
$scope.updateGraph();
117-
$scope.posLabel();
118-
}
119-
120-
//Loading over
121-
$scope.loading = false;
122-
});
88+
$scope.updateData(rep[0]);
89+
} else {
90+
console.error("ERROR: The data recieved from the server seems to be corrupted.");
91+
$scope.loadOffline();
92+
}
93+
}, function(error) {
94+
console.error("ERROR: Server error.\n", error);
95+
$scope.loadOffline();
96+
});
97+
98+
$scope.loadOffline = function () {
99+
//TODO: display message in front
100+
101+
DatasAdobeOffline.query(function(rep) {
102+
if (rep[0]) {
103+
$scope.updateData(rep[0]);
104+
} else {
105+
console.error("ERROR: All the datas seems corrupted. Please reload.");
106+
}
107+
}, function(error) {
108+
console.error("ERROR: Impossible to load the data. Please reload.");
109+
});
110+
}
111+
112+
$scope.updateData = function (data) {
113+
$scope.projects = data.repos;
114+
$scope.orgs = data.orgs;
115+
$scope.langs = data.langs;
116+
$scope.stats = data.stats;
117+
118+
$("#searchLang").autocomplete({
119+
source: $scope.objToNamedArray($scope.langs),
120+
select: function(e, q) {
121+
$scope.$apply(function () {
122+
$("#searchLang").val('Loading...');
123+
$scope.addFilter($scope.searchLang, q.item.value);
124+
$scope.searchLangInput = "";
125+
});
126+
return false;
127+
}
128+
});
129+
130+
$("#searchOrg").autocomplete({
131+
source: $scope.objToNamedArray($scope.orgs),
132+
select: function(e, q) {
133+
$scope.$apply(function () {
134+
$("#searchOrg").val('Loading...');
135+
$scope.addFilter($scope.searchOrg, q.item.value);
136+
$scope.searchOrgInput = "";
137+
});
138+
return false;
139+
}
140+
});
141+
142+
$scope.updateGraph();
143+
$scope.posLabel();
144+
145+
//Loading over
146+
$scope.loading = false;
147+
}
123148

124149
$scope.updateGraph = function() {
125150
// Filtering langs for only major ones
@@ -217,6 +242,8 @@ this.GitHubCtrl = function($scope, $sce, $filter, DatasAdobe, FeaturedHeader) {
217242
$scope.menuOpen = !$scope.menuOpen;
218243
}
219244
};
245+
246+
$(document).foundation();
220247

221248
/* ----------------------------------------------------------------------------
222249
Parrallax Scrolling

0 commit comments

Comments
 (0)