@@ -8,7 +8,7 @@ |
||
8 | 8 |
* Controller of the domainManagerApp |
9 | 9 |
*/ |
10 | 10 |
angular.module('codexApp.noteEdit', []) |
11 |
- .controller('NoteEditCtrl',['$scope', '$rootScope', '$state', 'FileService', function ($scope, $rootScope, $state, FileService) { |
|
11 |
+ .controller('NoteEditCtrl',['$scope', '$rootScope', '$state', '$timeout', 'FileService', function ($scope, $rootScope, $state, $timeout, FileService) { |
|
12 | 12 |
|
13 | 13 |
$scope.note = FileService.getCurrentNote(); |
14 | 14 |
console.log('-> Editing File: ' + $scope.note.path) |
@@ -48,9 +48,7 @@ angular.module('codexApp.noteView', []) |
||
48 | 48 |
var a = document.getElementsByTagName('a'), ajax; |
49 | 49 |
for (var i=0; i<a.length; ++i) { |
50 | 50 |
a[i].addEventListener('click', handleAnchor, false); |
51 |
- console.log(a[i].toString()); |
|
52 | 51 |
var parts = $scope.getUrlParts(a[i].toString()) |
53 |
- console.log(parts.protocol) |
|
54 | 52 |
if(parts.protocol == "file:"){ |
55 | 53 |
a[i].className += "internal-link"; |
56 | 54 |
} |
@@ -44,6 +44,7 @@ angular.module('codexApp') |
||
44 | 44 |
console.log("-> Saving user data..."); |
45 | 45 |
console.log(data); |
46 | 46 |
fs.writeFileSync(appDataPath + "/UserData.json", JSON.stringify(data), 'utf8'); |
47 |
+ appData = data; |
|
47 | 48 |
} |
48 | 49 |
|
49 | 50 |
var mkdirSync = function (path) { |
@@ -133,14 +134,44 @@ angular.module('codexApp') |
||
133 | 134 |
|
134 | 135 |
var getThumbnail = function(file_path) { |
135 | 136 |
var type = getFileType(file_path); |
137 |
+ var thumbs = appData.thumbs |
|
136 | 138 |
switch (type) { |
137 | 139 |
case "Markdown": |
138 |
- return ThumbnailService.createNoteThumbnail(file_path); |
|
140 |
+ var thumb = "" |
|
141 |
+ for (var i=0; i < thumbs.length; i++) { |
|
142 |
+ if (thumbs[i].file === file_path) { |
|
143 |
+ thumb = thumbs[i].path; |
|
144 |
+ break; |
|
145 |
+ } |
|
146 |
+ } |
|
147 |
+ console.log(thumb); |
|
148 |
+ if(thumb == "" || thumb == undefined){ |
|
149 |
+ console.log("> NO THUMBNAIL FOUND! GENERATING NEW ONE") |
|
150 |
+ thumb = saveThumbnail(file_path); |
|
151 |
+ } |
|
152 |
+ return thumb |
|
139 | 153 |
default: |
140 | 154 |
return ""; |
141 | 155 |
} |
142 | 156 |
} |
143 | 157 |
|
158 |
+ var saveThumbnail = function(file_path){ |
|
159 |
+ for (var i=0; i < appData.thumbs.length; i++) { |
|
160 |
+ if (appData.thumbs[i].file === file_path) { |
|
161 |
+ var fs = require("fs"); |
|
162 |
+ fs.unlink(appData.thumbs[i].path); |
|
163 |
+ appData.thumbs.splice(i) |
|
164 |
+ break; |
|
165 |
+ } |
|
166 |
+ } |
|
167 |
+ thumb = ThumbnailService.createNoteThumbnail(file_path, appDataPath); |
|
168 |
+ obj = { "file" : file_path, "path" : thumb } |
|
169 |
+ appData.thumbs.push(obj) |
|
170 |
+ saveAppData(appData) |
|
171 |
+ console.log("> Saving thumbnail: " + thumb ) |
|
172 |
+ return thumb |
|
173 |
+ } |
|
174 |
+ |
|
144 | 175 |
var isValidFile = function(file) { |
145 | 176 |
if(file != ".DS_Store" && file != "info.json") { |
146 | 177 |
var parts = file.split('.'); |
@@ -280,6 +311,7 @@ angular.module('codexApp') |
||
280 | 311 |
console.log(err); |
281 | 312 |
} else { |
282 | 313 |
console.log("-> FILE SAVED: " + file_path); |
314 |
+ saveThumbnail(file_path) |
|
283 | 315 |
} |
284 | 316 |
}); |
285 | 317 |
} |
@@ -552,4 +584,12 @@ angular.module('codexApp') |
||
552 | 584 |
return deleteFile(file); |
553 | 585 |
} |
554 | 586 |
|
587 |
+ this.getAppDataPath = function() { |
|
588 |
+ return appDataPath; |
|
589 |
+ } |
|
590 |
+ |
|
591 |
+ this.saveThumbnail = function(file_path){ |
|
592 |
+ return saveThumbnail(file_path); |
|
593 |
+ } |
|
594 |
+ |
|
555 | 595 |
}]) |
@@ -1,51 +1,65 @@ |
||
1 | 1 |
angular.module('codexApp') |
2 | 2 |
.service('ThumbnailService', [ '$rootScope', '$http', function($rootScope, $http) { |
3 | 3 |
|
4 |
- var createThumbnail = function(file_path) { |
|
4 |
+ var createThumbnail = function(file_path, app_data_path) { |
|
5 | 5 |
|
6 |
- // //console.log("-> Creating Thumbnail for " + file_path); |
|
7 |
- // var webshot = require('webshot'); |
|
8 |
- // var fs = require('fs'); |
|
9 |
- // var marked = require('marked'); |
|
10 |
- // |
|
11 |
- // var options = { |
|
12 |
- // screenSize: { |
|
13 |
- // width: 220 |
|
14 |
- // , height: 170 |
|
15 |
- // } |
|
16 |
- // , shotSize: { |
|
17 |
- // width: 220 |
|
18 |
- // , height: '170' |
|
19 |
- // } |
|
20 |
- // , userAgent: 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_2 like Mac OS X; en-us)' |
|
21 |
- // + ' AppleWebKit/531.21.20 (KHTML, like Gecko) Mobile/7B298g' |
|
22 |
- // , siteType:'html' |
|
23 |
- // }; |
|
24 |
- // |
|
25 |
- // var data = fs.readFileSync(file_path); |
|
26 |
- // var page_data = String.fromCharCode.apply(null, data); |
|
27 |
- // |
|
28 |
- // var thumbnail_path = getThumbnailName(file_path); |
|
29 |
- // var page = '<html><head><style>body {width: 210px;} body, h1, h2, h3, h4, h5, p, span, table, code, ul, ol { font-family: helvetica; overflow-wrap: break-word; font-weight: 300; } p, ul, ol, code { font-size: 11px;} h1 {font-size: 16px;} h2 {font-size: 14px;} h3 { font-size: 12px; font-weight: 400} code { font-family: monospace; }</style></head><body>' + marked(page_data); + '</body></html>'; |
|
30 |
- // var renderStream = webshot(page, thumbnail_path, options, function(err) { |
|
31 |
- // // screenshot now saved to hello_world.png |
|
32 |
- // }); |
|
33 |
- // //var file = fs.createWriteStream('google.png', {encoding: 'binary'}); |
|
34 |
- // |
|
35 |
- // |
|
36 |
- // |
|
37 |
- // console.log("-> Created thumbnail " + thumbnail_path); |
|
38 |
- // return thumbnail_path; |
|
6 |
+ //console.log("-> Creating Thumbnail for " + file_path); |
|
7 |
+ var webshot = require('webshot'); |
|
8 |
+ var fs = require('fs'); |
|
9 |
+ var marked = require('marked'); |
|
10 |
+ |
|
11 |
+ var options = { |
|
12 |
+ screenSize: { |
|
13 |
+ width: 220 |
|
14 |
+ , height: 170 |
|
15 |
+ } |
|
16 |
+ , shotSize: { |
|
17 |
+ width: 220 |
|
18 |
+ , height: '170' |
|
19 |
+ } |
|
20 |
+ , userAgent: 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_2 like Mac OS X; en-us)' |
|
21 |
+ + ' AppleWebKit/531.21.20 (KHTML, like Gecko) Mobile/7B298g' |
|
22 |
+ , siteType:'html' |
|
23 |
+ }; |
|
24 |
+ |
|
25 |
+ var data = fs.readFileSync(file_path); |
|
26 |
+ var page_data = String.fromCharCode.apply(null, data); |
|
27 |
+ console.log(app_data_path) |
|
28 |
+ var thumbnail_path = getThumbnailName(file_path, app_data_path); |
|
29 |
+ var page = '<html><head><style>body {width: 210px;} body, h1, h2, h3, h4, h5, p, span, table, code, ul, ol { font-family: helvetica; overflow-wrap: break-word; font-weight: 300; } p, ul, ol, code { font-size: 11px;} h1 {font-size: 16px;} h2 {font-size: 14px;} h3 { font-size: 12px; font-weight: 400} code { font-family: monospace; }</style></head><body>' + marked(page_data); + '</body></html>'; |
|
30 |
+ var renderStream = webshot(page, thumbnail_path, options, function(err) { |
|
31 |
+ // screenshot now saved to hello_world.png |
|
32 |
+ }); |
|
33 |
+ //var file = fs.createWriteStream('google.png', {encoding: 'binary'}); |
|
34 |
+ |
|
35 |
+ |
|
36 |
+ |
|
37 |
+ console.log("-> Created thumbnail " + thumbnail_path); |
|
38 |
+ return thumbnail_path; |
|
39 | 39 |
} |
40 | 40 |
|
41 |
- var getThumbnailName = function(file_path) { |
|
41 |
+ var getThumbnailName = function(file_path, app_data_path) { |
|
42 | 42 |
var filename = file_path.split('\\').pop().split('/').pop(); |
43 | 43 |
var name = filename.split('.'); |
44 | 44 |
//if (lastIndex < 1) return ""; |
45 | 45 |
var path = file_path.split('/'); |
46 | 46 |
path.pop(); |
47 | 47 |
var thumb_path = path.join('/'); |
48 |
- return thumb_path + "/" + name[0] + ".thumb.png"; |
|
48 |
+ //return thumb_path + "/" + name[0] + ".thumb.png"; |
|
49 |
+ var date = new Date(); |
|
50 |
+ var components = [ |
|
51 |
+ date.getYear(), |
|
52 |
+ date.getMonth(), |
|
53 |
+ date.getDate(), |
|
54 |
+ date.getHours(), |
|
55 |
+ date.getMinutes(), |
|
56 |
+ date.getSeconds(), |
|
57 |
+ date.getMilliseconds() |
|
58 |
+ ]; |
|
59 |
+ |
|
60 |
+ var id = components.join(""); |
|
61 |
+ |
|
62 |
+ return app_data_path + "/thumbs/" + id + ".png" |
|
49 | 63 |
} |
50 | 64 |
|
51 | 65 |
var thumbnailExists = function(file_path) { |
@@ -60,9 +74,9 @@ angular.module('codexApp') |
||
60 | 74 |
return fs.existsSync(url); |
61 | 75 |
} |
62 | 76 |
|
63 |
- this.createNoteThumbnail = function(file_path) { |
|
77 |
+ this.createNoteThumbnail = function(file_path, app_data_path) { |
|
64 | 78 |
if(thumbnailExists(file_path) == false){ |
65 |
- return createThumbnail(file_path); |
|
79 |
+ return createThumbnail(file_path, app_data_path); |
|
66 | 80 |
} |
67 | 81 |
return getThumbnailName(file_path); |
68 | 82 |
} |