diff options
author | Phie <phie@phie.ovh> | 2018-09-08 22:48:52 +0300 |
---|---|---|
committer | Phie <phie@phie.ovh> | 2018-09-08 22:48:52 +0300 |
commit | edf72ff974788af53ccacaacff414f3a64d503fc (patch) | |
tree | aabb024cfe3a615bf98ba5da1c820bafa3d3bcc8 /js | |
parent | 4a4543a9010bf54c0f2bf9e09d3e3f7bd434a03e (diff) |
cleaning
Diffstat (limited to 'js')
-rwxr-xr-x | js/browsers/browser.js | 539 | ||||
-rwxr-xr-x | js/browsers/design.css | 152 | ||||
-rwxr-xr-x | js/browsers/file-browser.js | 109 | ||||
-rwxr-xr-x | js/browsers/note.js | 24 | ||||
-rwxr-xr-x | js/browsers/note_card_view.js | 250 | ||||
-rwxr-xr-x | js/browsers/search.js | 86 |
6 files changed, 0 insertions, 1160 deletions
diff --git a/js/browsers/browser.js b/js/browsers/browser.js deleted file mode 100755 index 9d10e5c..0000000 --- a/js/browsers/browser.js +++ /dev/null @@ -1,539 +0,0 @@ -var initPath = "recentdb://" -var currentPath; -var currentTask = undefined; -var noteCardViewGrid = undefined; -var notePath = [] -var wasNewNote = false -var dontOpen = false; -var currentNotePath = undefined -const { - ipcRenderer, - remote, - app -} = require('electron'); -const Store = require('electron-store'); -const store = new Store(); -var noteCacheStr = String(store.get("note_cache")) -if (noteCacheStr == "undefined") - noteCacheStr = "{}" -console.log("cache loaded " + noteCacheStr) - -var oldNotes = JSON.parse(noteCacheStr); -var main = remote.require("./main.js"); -var SettingsHelper = require("./settings/settings_helper").SettingsHelper -var settingsHelper = new SettingsHelper() -var TextGetterTask = function (list) { - this.list = list; - this.current = 0; - this.continue = true; - this.stopAt = 50; -} - -TextGetterTask.prototype.startList = function () { - this.getNext(); -} - -TextGetterTask.prototype.getNext = function () { - if (this.current >= this.stopAt) { - console.log("save cache ") - store.set("note_cache", JSON.stringify(oldNotes)) - return; - } - if (this.list[this.current] instanceof Note) { - var opener = new NoteOpener(this.list[this.current]) - var myTask = this; - var note = this.list[this.current] - var fast = false; - //should we go fast or slow refresh ? - for (var i = this.current; i < this.stopAt && i < this.list.length && i < oldNotes.length; i++) { - if (oldNotes[this.list[i].path] == undefined) { - fast = true; - break; - } - } - setTimeout(function () { - try { - opener.getMainTextMetadataAndPreviews(function (txt, metadata, previews) { - if (myTask.continue) { - if (txt != undefined) - note.text = txt.substring(0, 200); - if (metadata != undefined) - note.metadata = metadata; - note.previews = previews; - oldNotes[note.path] = note; - noteCardViewGrid.updateNote(note) - noteCardViewGrid.msnry.layout(); - - myTask.getNext(); - } - }); - } catch (error) { - console.log(error); - } - myTask.current++; - }, !fast ? 1000 : 100) - - } else { - this.current++; - this.getNext(); - } - -} - -var NewNoteCreationTask = function (callback) { - var path = currentPath; - if (path == initPath || path.startsWith("keyword://")) - path = main.getNotePath(); - var fs = require('fs'); - if (!fs.exists(path)) { - var mkdirp = require('mkdirp'); - mkdirp.sync(path); - } - - var fb = new FileBrowser(path); - console.log(path + " fefef") - var task = this; - fb.list(function (files) { - task.files = files; - var name = "untitled.sqd"; - var sContinue = true; - var i = 1; - while (sContinue) { - sContinue = false - for (let file of files) { - if (file.name == name) { - sContinue = true; - i++; - name = "untitled " + i + ".sqd"; - } - } - } - callback(path + "/" + name) - - }); -} - -String.prototype.replaceAll = function (search, replacement) { - var target = this; - return target.replace(new RegExp(search, 'g'), replacement); -}; - -function openNote(notePath) { - currentNotePath = notePath - const electron = require('electron') - const remote = electron.remote; - const BrowserWindow = remote.BrowserWindow; - const path = require('path') - //var win = new BrowserWindow({ width: 800, height: 600 }); - if (!hasLoadedOnce) - $(loadingView).fadeIn(); - //$(browserElem).faceOut(); - var rimraf = require('rimraf'); - const tmp = path.join(main.getPath("temp"), "tmpquicknote"); - rimraf(tmp, function () { - var fs = require('fs'); - - fs.mkdir(tmp, function (e) { - fs.readFile(__dirname + '/reader/reader.html', 'utf8', function (err, data) { - if (err) { - fs.rea - console.log("error ") - return console.log(err); - } - const index = path.join(tmp, 'reader.html'); - fs.writeFileSync(index, data.replace(new RegExp('<!ROOTPATH>', 'g'), __dirname + '/')); - /* var size = remote.getCurrentWindow().getSize(); - var pos = remote.getCurrentWindow().getPosition(); - var win = new BrowserWindow({ - width: size[0], - height: size[1], - x: pos[0], - y: pos[1], - frame: false - }); - console.log("w " + remote.getCurrentWindow().getPosition()[0]) - const url = require('url') - win.loadURL(url.format({ - pathname: path.join(__dirname, 'tmp/reader.html'), - protocol: 'file:', - query: { - 'path': notePath - }, - slashes: true - }))*/ - const url = require('url') - - if (!hasLoadedOnce) { - webview.setAttribute("src", url.format({ - pathname: index, - protocol: 'file:', - query: { - 'path': notePath, - 'tmppath': tmp + "/" - }, - slashes: true - })); - } else - webview.send('loadnote', notePath); - webview.style = "position:fixed; top:0px; left:0px; height:100%; width:100%; z-index:100; right:0; bottom:0;" - //to resize properly - hasLoadedOnce = true; - }); - - - }); - - }) -} - -function onDragEnd(gg) { - console.log("ondragend") - dontOpen = true; -} - -function refreshKeywords() { - var KeywordsDBManager = require("./keywords/keywords_db_manager").KeywordsDBManager; - var keywordsDBManager = new KeywordsDBManager(main.getNotePath() + "/quickdoc/keywords/" + main.getAppUid()) - keywordsDBManager.getFlatenDB(function (error, data) { - var keywordsContainer = document.getElementById("keywords"); - keywordsContainer.innerHTML = ""; - var dataArray = [] - for (let key in data) { - if (data[key].length == 0) - continue; - dataArray.push(key) - } - dataArray.sort(Utils.caseInsensitiveSrt) - for (let key of dataArray) { - - var keywordElem = document.createElement("a"); - keywordElem.classList.add("mdl-navigation__link") - keywordElem.innerHTML = key; - keywordElem.setAttribute("href", ""); - keywordElem.onclick = function () { - list("keyword://" + key, false); - return false; - } - keywordsContainer.appendChild(keywordElem) - } - }) -} - -function searchInNotes(searching) { - resetGrid(false) - var settingsHelper = require("./settings/settings_helper").SettingsHelper - var SettingsHelper = new settingsHelper(); - var Search = require("./browsers/search").Search - var browser = this; - notes = [] - var callback = function () { - - } - callback.update = function (note) { - console.log("found " + note.path) - note = new Note(note.title, note.text.substring(0, 200), note.path, note.metadata) - browser.noteCardViewGrid.addNote(note) - notes.push(note) - - } - callback.onEnd = function (list) { - console.log("onEnd " + list.length) - - - } - search = new Search(searching, SettingsHelper.getNotePath(), callback) - search.start() - -} - -function resetGrid(discret) { - var grid = document.getElementById("page-content"); - var scroll = 0; - if (discret) - scroll = document.getElementById("grid-container").scrollTop; - grid.innerHTML = ""; - noteCardViewGrid = new NoteCardViewGrid(grid, discret, onDragEnd); - this.noteCardViewGrid = noteCardViewGrid; - noteCardViewGrid.onFolderClick(function (folder) { - list(folder.path) - }) - noteCardViewGrid.onNoteClick(function (note) { - if (!dontOpen) - openNote(note.path) - dontOpen = false; - // var reader = new Writer(note,""); - // reader.extractNote() - }) - - - noteCardViewGrid.onMenuClick(function (note) { - mNoteContextualDialog.show(note) - }) -} - -class ContextualDialog { - constructor() { - this.showDelete = true; - this.showArchive = true; - this.showPin = true; - this.dialog = document.querySelector('#contextual-dialog'); - this.nameInput = this.dialog.querySelector('#name-input'); - this.deleteButton = this.dialog.querySelector('.delete-button'); - this.archiveButton = this.dialog.querySelector('#archive-button'); - this.pinButton = this.dialog.querySelector('#pin-button'); - this.cancel = this.dialog.querySelector('.cancel'); - this.ok = this.dialog.querySelector('.ok'); - var context = this; - this.cancel.onclick = function () { - context.dialog.close(); - } - } - - show() { - this.showDelete ? $(this.deleteButton).show() : $(this.deleteButton).hide(); - this.showArchive ? $(this.archiveButton).show() : $(this.archiveButton).hide(); - this.showPin ? $(this.pinButton).show() : $(this.pinButton).hide(); - this.dialog.showModal(); - this.nameInput.focus() - } -} - -class NewFolderDialog extends ContextualDialog { - constructor() { - super(); - this.showDelete = false; - this.showArchive = false; - this.showPin = false; - } - - show() { - var context = this; - - this.ok.onclick = function () { - var fb = new FileBrowser(currentPath); - fb.createFolder(context.nameInput.value, function () { - list(currentPath, true) - context.dialog.close(); - }) - } - super.show() - - } -} - -class NoteContextualDialog extends ContextualDialog { - constructor() { - super(); - } - - show(note) { - var context = this; - this.nameInput.value = note.title; - this.deleteButton.onclick = function () { - NoteUtils.deleteNote(note.path, function () { - context.dialog.close(); - list(currentPath, true) - }) - } - this.archiveButton.onclick = function () { - var db = new RecentDBManager(main.getNotePath() + "/quickdoc/recentdb/" + main.getAppUid()) - db.removeFromDB(NoteUtils.getNoteRelativePath(main.getNotePath(), note.path), function () { - context.dialog.close(); - list(currentPath, true) - }); - - } - if (note.isPinned == true) { - this.pinButton.innerHTML = "Unpin" - } else this.pinButton.innerHTML = "Pin" - - this.pinButton.onclick = function () { - var db = new RecentDBManager(main.getNotePath() + "/quickdoc/recentdb/" + main.getAppUid()) - if (note.isPinned == true) - db.unpin(NoteUtils.getNoteRelativePath(main.getNotePath(), note.path), function () { - context.dialog.close(); - list(currentPath, true) - }); - - else - db.pin(NoteUtils.getNoteRelativePath(main.getNotePath(), note.path), function () { - context.dialog.close(); - list(currentPath, true) - }); - } - this.ok.onclick = function () { - NoteUtils.renameNote(note.path, context.nameInput.value + ".sqd", function () { - list(currentPath, true) - }) - - context.dialog.close(); - } - super.show() - - } -} - -var mNoteContextualDialog = new NoteContextualDialog() -var mNewFolderDialog = new NewFolderDialog() - - -function list(pathToList, discret) { - if (pathToList == undefined) - pathToList = currentPath; - console.log("listing path " + pathToList); - currentPath = pathToList; - if (pathToList == settingsHelper.getNotePath() || pathToList == initPath || pathToList.startsWith("keyword://")) { - if (pathToList != settingsHelper.getNotePath()) { - $("#add-directory-button").hide() - } else - $("#add-directory-button").show() - - $("#back_arrow").hide() - } else { - $("#back_arrow").show() - $("#add-directory-button").show() - } - - resetGrid(discret); - var noteCardViewGrid = this.noteCardViewGrid - var notes = []; - notePath = []; - - var fb = new FileBrowser(pathToList); - fb.list(function (files) { - if (currentTask != undefined) - currentTask.continue = false - if (files.length > 0) { - $("#emty-view").fadeOut("fast"); - } else - $("#emty-view").fadeIn("fast"); - for (let file of files) { - var filename = getFilenameFromPath(file.path); - if (file.isFile && filename.endsWith(".sqd")) { - var oldNote = oldNotes[file.path]; - - var noteTestTxt = new Note(stripExtensionFromName(filename), oldNote != undefined ? oldNote.text : "", file.path, oldNote != undefined ? oldNote.metadata : undefined, oldNote != undefined ? oldNote.previews : undefined); - noteTestTxt.isPinned = file.isPinned - notes.push(noteTestTxt) - } else if (!file.isFile) { - - notes.push(file) - } - notePath.push(file.path) - } - noteCardViewGrid.setNotesAndFolders(notes) - if (discret) { - document.getElementById("grid-container").scrollTop = scroll; - console.log("scroll : " + scroll) - - } - currentTask = new TextGetterTask(notes); - console.log("stopping and starting task") - currentTask.startList(); - - }); - -} -list(initPath) -refreshKeywords(); - -function minimize() { - remote.BrowserWindow.getFocusedWindow().minimize(); -} - -function maximize() { - if (remote.BrowserWindow.getFocusedWindow().isMaximized()) - remote.BrowserWindow.getFocusedWindow().unmaximize(); - else - remote.BrowserWindow.getFocusedWindow().maximize(); -} - -function closeW() { - remote.app.exit(0); - console.log("cloose") -} - -function toggleSearch() { - $("#search-container").slideToggle(); -} - - -main.setMergeListener(function () { - list(initPath, true) -}) - -document.getElementById("add-note-button").onclick = function () { - new NewNoteCreationTask(function (path) { - console.log("found " + path) - wasNewNote = true; - var db = new RecentDBManager(main.getNotePath() + "/quickdoc/recentdb/" + main.getAppUid()) - db.addToDB(NoteUtils.getNoteRelativePath(main.getNotePath(), path)); - openNote(path) - }) -} - -document.getElementById("add-directory-button").onclick = function () { - mNewFolderDialog.show(); -} - - -document.getElementById("search-input").onkeydown = function (event) { - if (event.key === 'Enter') { - searchInNotes(this.value) - } -} - -document.getElementById("back_arrow").addEventListener("click", function () { - list(getParentFolderFromPath(currentPath)) -}); - -function getNotePath() { - - return main.getNotePath() -} - -function loadNextNotes() { - browser.noteCardViewGrid.addNext(15); - currentTask.stopAt += 15; - currentTask.getNext() -} - -var browser = this -document.getElementById("grid-container").onscroll = function () { - if (this.offsetHeight + this.scrollTop >= this.scrollHeight - 80) { - loadNextNotes(); - - } -} -var webview = document.getElementById("writer-webview") - -webview.addEventListener('ipc-message', event => { - if (event.channel == "exit") { - webview.style = "position:fixed; top:0px; left:0px; height:0px; width:0px; z-index:100; right:0; bottom:0;" - //$(browserElem).faceIn(); - $("#no-drag-bar").hide() - if (wasNewNote) - list(currentPath, true) - else if (currentTask != undefined) { - var noteIndex - if ((noteIndex = notePath.indexOf(currentNotePath)) == -1) { - noteIndex = 0; - } - currentTask.current = noteIndex; - currentTask.getNext() - } - wasNewNote = false; - refreshKeywords() - - } else if (event.channel == "loaded") { - $(loadingView).fadeOut(); - $("#no-drag-bar").show() - - } -}); -var hasLoadedOnce = false -webview.addEventListener('dom-ready', () => { - webview.openDevTools() -}) -var loadingView = document.getElementById("loading-view") -//var browserElem = document.getElementById("browser")
\ No newline at end of file diff --git a/js/browsers/design.css b/js/browsers/design.css deleted file mode 100755 index 7a1285a..0000000 --- a/js/browsers/design.css +++ /dev/null @@ -1,152 +0,0 @@ -.demo-card-wide.mdl-card { - width: 202px; - min-height: 0px; - margin: 5px; - cursor: pointer; -} - -.mdl-card__supporting-text{ - padding-bottom: 0px !important; -} - -.note-card-view :hover, -.folder-card-view :hover { - background-color: rgb(230, 230, 230); - -webkit-transition: background-color 250ms linear; - -ms-transition: background-color 250ms linear; - transition: background-color 250ms linear; -} - -.demo-card-wide>.mdl-card__title { - color: black; -} - -.packery-drop-placeholder { - outline: 3px dashed #444; - outline-offset: -6px; - /* transition position changing */ - -webkit-transition: -webkit-transform 0.2s; - transition: transform 0.2s; -} - - -/* highlight drag & drop */ - - -/* jQuery UI Draggable adds ui-draggable-dragging */ - -.ui-draggable-dragging, -.is-positioning-post-drag { - background: #C90; - z-index: 20000 !important; - /* keep dragged item on top */ -} - -.demo-card-wide>.mdl-card__menu { - color: #fff; -} - -body { - background: #fafafa; - position: relative; -} - -#page-content { - position: relative; - margin: 0 auto; -} - -#grid-container { - margin: 0 auto; - position: absolute; - width: 100%; - height: 100%; - overflow-y: auto; -} - -.big-text { - font-size: 40px; -} - -.medium-text { - font-size: 30px; -} - -@media (min-width: 1314px) { - #grid-container { - max-width: 1074px; - left: calc(50% - 537px); - } -} - -.card-title { - font-size: 24px; - font-weight: 300; - line-height: normal; - color: black; - margin: 0px; -} - -.card-text { - line-height: initial; - margin-bottom: 10px; - margin-right: 20px; - word-wrap: break-word; - color: rgba(0,0,0,.87); - -} - -.card-title:hover { - background: none; -} - -.card-text:hover { - background: none; -} - -.mdl-layout__header { - -webkit-app-region: drag; -} - -.mdl-layout__header .mdl-layout__drawer-button, -.mdl-layout__header button, -.mdl-layout__header .mdl-textfield { - -webkit-app-region: no-drag; -} - -.folder-icon { - width: 50px; -} - -.card-more-button { - right: 0px; - background: inherit !important; - position: absolute !important; -} - -.keywords{ - margin-bottom:16px; -} - -.keyword { - margin-right: 3px; - margin-top: 3px; - padding: 3px; - background: #D2D2D2; - display: inline-block; -} - -.card-rating{ - margin-right:10px; - float:right; -} - -.card-medias{ - margin-left:-20px; - margin-right:-5px; - background: black; - border-radius: 2px; -} -.card-medias img{ - width:100%; -} diff --git a/js/browsers/file-browser.js b/js/browsers/file-browser.js deleted file mode 100755 index 3777106..0000000 --- a/js/browsers/file-browser.js +++ /dev/null @@ -1,109 +0,0 @@ -var fs = require("fs"); -const pathTool = require('path') -var getParentFolderFromPath = require('path').dirname; -var FileBrowser = function (path) { - this.path = path; -} - -FileBrowser.prototype.createFolder = function (name, callback) { - fs.mkdir(pathTool.join(this.path, name), function (e) { - callback(); - }); - -} - -FileBrowser.prototype.list = function (callback) { - var { - ipcRenderer, - remote - } = require('electron'); - var main = remote.require("./main.js"); - var mainPath = main.getNotePath(); - - if (this.path == "recentdb://") { - console.log("getting recent") - var db = new RecentDBManager(mainPath + "/quickdoc/recentdb/" + main.getAppUid()) - db.getFlatenDB(function (err, flaten, pin) { - console.log(JSON.stringify(flaten)) - var files = []; - for (let filePath of pin) { - var filename = filePath; - filePath = mainPath + "/" + filePath - file = new File(filePath, true, filename); - file.isPinned = true; - files.push(file) - } - for (let filePath of flaten) { - if (pin.indexOf(filePath) != -1) - continue; - var filename = filePath; - filePath = mainPath + "/" + filePath - file = new File(filePath, true, filename); - files.push(file) - } - callback(files) - }) - } else if (this.path.startsWith("keyword://")) { - console.log("getting keyword") - var KeywordsDBManager = require("./keywords/keywords_db_manager").KeywordsDBManager; - var keywordsDBManager = new KeywordsDBManager(main.getNotePath() + "/quickdoc/keywords/" + main.getAppUid()) - var filebrowser = this; - keywordsDBManager.getFlatenDB(function (error, data) { - var files = []; - console.log("keyword " + filebrowser.path.substring("keyword://".length)) - for (let filePath of data[filebrowser.path.substring("keyword://".length)]) { - var filename = filePath; - console.log("file " + filePath) - - filePath = mainPath + "/" + filePath - file = new File(filePath, true, filename); - files.push(file) - } - callback(files) - }) - } else { - fs.readdir(this.path, (err, dir) => { - //console.log(dir); - var files = []; - var dirs_in = []; - var files_in = []; - for (let filePath of dir) { - var filename = filePath; - if (filename == "quickdoc" || filename.startsWith(".")) - continue; - filePath = this.path + "/" + filePath - var stat = fs.statSync(filePath); - file = new File(filePath, stat.isFile(), filename); - console.log(filePath) - if (stat.isFile()) - files_in.push(file) - else - dirs_in.push(file) - - } - files = files.concat(dirs_in) - files = files.concat(files_in) - - callback(files) - }); - } -} - -var File = function (path, isFile, name, extension) { - this.path = path; - this.isFile = isFile; - this.name = name; - this.extension = extension; - -} -File.prototype.getName = function () { - return getFilenameFromPath(this.path); -} - -function getFilenameFromPath(path) { - return path.replace(/^.*[\\\/]/, ''); -} - -function stripExtensionFromName(name) { - return name.replace(/\.[^/.]+$/, "") -}
\ No newline at end of file diff --git a/js/browsers/note.js b/js/browsers/note.js deleted file mode 100755 index a227c83..0000000 --- a/js/browsers/note.js +++ /dev/null @@ -1,24 +0,0 @@ - - -var Note = function(title, text, path, metadata, previews){ - this.title = title; - this.text = text; - this.path = path; - this.previews = previews; - if(metadata == undefined){ - this.metadata = new NoteMetadata(); - this.metadata.creation_date = Date.now(); - this.metadata.last_modification_date = this.metadata.creation_date; - } - else - this.metadata = metadata; - -} - -var NoteMetadata = function(){ - this.creation_date = "" - this.last_modification_date = "" - this.keywords = [] - this.rating = -1; -} -exports.Note = Note
\ No newline at end of file diff --git a/js/browsers/note_card_view.js b/js/browsers/note_card_view.js deleted file mode 100755 index 9471a91..0000000 --- a/js/browsers/note_card_view.js +++ /dev/null @@ -1,250 +0,0 @@ -var NoteCardView = function (elem) { - this.elem = elem; - this.init(); -} -NoteCardView.prototype.setNote = function (note) { - this.note = note; - if (note.title.indexOf("untitled") == 0) - this.cardTitleText.innerHTML = "" - else - this.cardTitleText.innerHTML = note.title; - var date = new Date(note.metadata.last_modification_date).toLocaleDateString(); - this.cardText.innerHTML = note.text; - this.cardDate.innerHTML = date; - if(note.metadata.rating>0) - this.cardRating.innerHTML = note.metadata.rating+"★" - this.cardKeywords.innerHTML = ""; - this.cardText.classList.remove("big-text") - this.cardText.classList.remove("medium-text") - - if (note.text.length < 40 && this.cardTitleText.innerHTML == "") - this.cardText.classList.add("big-text") - else if (note.text.length < 100 && this.cardTitleText.innerHTML == "") { - this.cardText.classList.add("medium-text") - - } - if (typeof note.metadata.keywords[Symbol.iterator] === 'function') - for (let keyword of note.metadata.keywords) { - console.log("keyword " + keyword) - keywordSpan = document.createElement('span'); - keywordSpan.innerHTML = keyword; - keywordSpan.classList.add("keyword"); - this.cardKeywords.appendChild(keywordSpan) - } - this.cardMedias.innerHTML = ""; - if(note.previews != undefined) - for (let preview of note.previews) { - var img = document.createElement('img'); - img.src = preview; - this.cardMedias.appendChild(img); - } - -} - -NoteCardView.prototype.init = function () { - this.elem.classList.add("mdl-card"); - this.elem.classList.add("note-card-view"); - - this.menuButton = document.createElement('button'); - - this.menuButton.classList.add("mdl-button"); - - this.menuButton.classList.add("mdl-js-button"); - this.menuButton.classList.add("mdl-button--icon"); - this.menuButton.classList.add("card-more-button"); - - var menuButtonIcon = document.createElement('li'); - menuButtonIcon.classList.add("material-icons"); - menuButtonIcon.innerHTML = "more_vert"; - this.menuButton.appendChild(menuButtonIcon); - this.elem.classList.add("mdl-shadow--2dp"); - this.cardContent = document.createElement('div'); - this.cardContent.classList.add("mdl-card__supporting-text"); - this.cardContent.appendChild(this.menuButton) - this.cardText = document.createElement('div'); - this.cardText.classList.add("card-text"); - - this.cardTitleText = document.createElement('h2'); - this.cardTitleText.classList.add("card-title"); - this.cardContent.appendChild(this.cardTitleText) - this.cardContent.appendChild(this.cardText) - this.cardRating = document.createElement('div'); - this.cardRating.classList.add("card-rating"); - this.cardContent.appendChild(this.cardRating) - this.cardDate = document.createElement('div'); - this.cardDate.classList.add("card-date"); - this.cardContent.appendChild(this.cardDate) - - this.cardKeywords = document.createElement('div'); - this.cardKeywords.classList.add("keywords"); - this.cardContent.appendChild(this.cardKeywords) - - this.cardMedias = document.createElement('div'); - this.cardMedias.classList.add("card-medias"); - this.cardContent.appendChild(this.cardMedias) - - this.elem.appendChild(this.cardContent); - -} - -var Masonry = require('masonry-layout'); -var NoteCardViewGrid = function (elem, discret, dragCallback) { - - this.elem = elem; - this.discret = discret; - this.init(); - this.dragCallback = dragCallback; -} - - - - -NoteCardViewGrid.prototype.init = function () { - this.noteCards = []; - this.lastAdded = 0; - this.notes = [] - this.msnry = new Masonry(this.elem, { - // options - itemSelector: '.demo-card-wide.mdl-card', - fitWidth: true, - columnWidth: 212, - transitionDuration: this.discret ? 0 : "0.6s", - animationOptions: { - - queue: false, - isAnimated: false - }, - }); - - -} - -NoteCardViewGrid.prototype.onFolderClick = function (callback) { - this.onFolderClick = callback; -} - -NoteCardViewGrid.prototype.onNoteClick = function (callback) { - this.onNoteClick = callback; -} - -NoteCardViewGrid.prototype.onMenuClick = function (callback) { - this.onMenuClick = callback; -} - - -NoteCardViewGrid.prototype.updateNote = function (note) { - for (var i = 0; i < this.noteCards.length; i++) { - var noteCard = this.noteCards[i]; - if (noteCard.note.path == note.path) { - noteCard.setNote(note); - } - } -} - -NoteCardViewGrid.prototype.setNotesAndFolders = function (notes) { - this.notes = notes; - this.noteCards = []; - this.lastAdded = 0; - this.addNext(45); -} -NoteCardViewGrid.prototype.addNote = function(note){ - this.notes.push(note) - this.addNext(1); - -} -NoteCardViewGrid.prototype.addNext = function (num) { - var lastAdded = this.lastAdded - for (i = this.lastAdded; i < this.notes.length && i < num + lastAdded; i++) { - var note = this.notes[i] - if (note instanceof Note) { - var noteElem = document.createElement("div"); - noteElem.classList.add("demo-card-wide") - noteElem.classList.add("isotope-item") - var noteCard = new NoteCardView(noteElem); - noteCard.setNote(note); - noteElem.note = note; - this.noteCards.push(noteCard); - this.elem.appendChild(noteElem) - this.msnry.appended(noteElem) - - $(noteElem).bind('click', { - note: note, - callback: this.onNoteClick - }, function (event) { - if (!$(this).hasClass('noclick')) { - var data = event.data; - data.callback(data.note) - } - }); - - $(noteCard.menuButton).bind('click', { - note: note, - callback: this.onMenuClick - }, function (event) { - if (!$(this).hasClass('noclick')) { - var data = event.data; - data.callback(data.note) - return false; - } - }); - } else { - var folderElem = document.createElement("div"); - folderElem.classList.add("demo-card-wide") - folderElem.classList.add("isotope-item") - - $(folderElem).bind('click', { - folder: note, - callback: this.onFolderClick - }, function (event) { - if (!$(this).hasClass('noclick')) { - var data = event.data; - data.callback(data.folder) - } - }); - - - var folderCard = new FolderView(folderElem); - folderCard.setFolder(note); - this.elem.appendChild(folderElem) - this.msnry.appended(folderElem) - } - this.lastAdded = i + 1; - } - - // make all grid-items draggable - var grid = this; - - this.msnry.layout(); - this.msnry.options.transitionDuration = "0.6s" //restore even when discret - -} - - - -var FolderView = function (elem) { - this.elem = elem; - this.init(); -} -FolderView.prototype.setFolder = function (folder) { - this.folder = folder; - this.cardTitle.innerHTML = folder.getName(); -} - -FolderView.prototype.init = function () { - this.elem.classList.add("mdl-card"); - this.elem.classList.add("folder-card-view"); - this.elem.classList.add("mdl-shadow--2dp"); - this.cardContent = document.createElement('div'); - this.cardContent.classList.add("mdl-card__supporting-text"); - this.img = document.createElement('img'); - this.img.classList.add("folder-icon") - this.img.src = "img/directory.png"; - this.cardContent.appendChild(this.img); - - this.cardTitle = document.createElement('h2'); - this.cardTitle.classList.add("card-title"); - this.cardTitle.style = "display:inline;margin-left:5px;" - this.cardContent.appendChild(this.cardTitle); - this.elem.appendChild(this.cardContent); - -}
\ No newline at end of file diff --git a/js/browsers/search.js b/js/browsers/search.js deleted file mode 100755 index cfefd26..0000000 --- a/js/browsers/search.js +++ /dev/null @@ -1,86 +0,0 @@ -var fs = require("fs"); -var Search = function (keyword, path, callback) { - this.keyword = keyword.toLowerCase(); - this.callback = callback; - this.path = path -} - -Search.prototype.start = function () { - this.fileList = []; - this.toVisit = []; - this.result = []; - var search = this; - - this.recursiveVisit(this.path, function () { - if (search.fileList.length > 0) { - search.searchInFiles(search.callback); - } - }) -} -Search.prototype.searchInFiles = function (callback) { - var search = this; - if (search.fileList.length > 0) { - this.searchInFile(search.fileList.pop(), function () { - search.searchInFiles(callback) - }) - } else - callback.onEnd(this.result) - -} - -function getFilenameFromPath(path) { - return path.replace(/^.*[\\\/]/, ''); -} - -function stripExtensionFromName(name) { - return name.replace(/\.[^/.]+$/, "") -} -Search.prototype.searchInFile = function (filePath, callback) { - console.log("searchInFile " + filePath) - var NoteOpener = require("../note/note-opener").NoteOpener - var Note = require("./note").Note - - var opener = new NoteOpener(new Note(filePath, "", filePath, undefined)) - var search = this; - try { - console.log("opening") - - opener.getMainTextAndMetadata(function (txt, metadata) { - var fileName = stripExtensionFromName(getFilenameFromPath(filePath)); - console.log("opened") - if (fileName.toLowerCase().indexOf(search.keyword) >= 0 || txt !== undefined && txt.toLowerCase().indexOf(search.keyword) >= 0 || metadata !== undefined && metadata.keywords.indexOf(search.keyword) >= 0) { - search.result.push(new Note(fileName, txt, filePath, metadata)) - search.callback.update(new Note(stripExtensionFromName(getFilenameFromPath(filePath)), txt, filePath, metadata)) - console.log("found in " + filePath) - - } - callback() - }); - } catch (error) { - console.log(error); - callback() - } -} -Search.prototype.recursiveVisit = function (path, callback) { - var search = this; - console.log("visiting " + path) - fs.readdir(path, (err, dir) => { - - if (!err) - for (var filePath of dir) { - filePath = path + "/" + filePath; - var stat = fs.statSync(filePath); - - if (!stat.isFile()) { - search.toVisit.push(filePath) - } else if (filePath.endsWith(".sqd")) { - search.fileList.push(filePath) - } - } - if (search.toVisit.length > 0) { - search.recursiveVisit(search.toVisit.pop(), callback) - } else - callback() - }); -} -exports.Search = Search
\ No newline at end of file |