From 476cabd10952f026f331754baf9846b1aad917cd Mon Sep 17 00:00:00 2001 From: Jason Croft Date: Mon, 9 May 2016 17:07:02 -0400 Subject: Attach to snippet classes. --- public/js/index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'public/js') diff --git a/public/js/index.js b/public/js/index.js index 3f0ed593..0b10c9e0 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -496,12 +496,14 @@ var ui = { export: { dropbox: $(".ui-save-dropbox"), googleDrive: $(".ui-save-google-drive"), - gist: $(".ui-save-gist") + gist: $(".ui-save-gist"), + snippet: $(".ui-save-snippet") }, import: { dropbox: $(".ui-import-dropbox"), googleDrive: $(".ui-import-google-drive"), gist: $(".ui-import-gist"), + snippet: $(".ui-import-snippet"), clipboard: $(".ui-import-clipboard") }, beta: { -- cgit v1.3.1 From 70f6e5bc2cbdb15ff48bdf49b09d7c4bb78ea4ba Mon Sep 17 00:00:00 2001 From: Jason Croft Date: Mon, 9 May 2016 22:38:13 -0400 Subject: Define events for snippet actions --- public/js/index.js | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'public/js') diff --git a/public/js/index.js b/public/js/index.js index 0b10c9e0..17516169 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -1136,6 +1136,8 @@ ui.toolbar.export.googleDrive.click(function (e) { }); //export to gist ui.toolbar.export.gist.attr("href", noteurl + "/gist"); +//export to snippet +ui.toolbar.export.snippet.attr("href", noteurl + "/snippet"); //import from dropbox ui.toolbar.import.dropbox.click(function () { var options = { @@ -1188,6 +1190,10 @@ function buildImportFromGoogleDrive() { ui.toolbar.import.gist.click(function () { //na }); +//import from snippet +ui.toolbar.import.snippet.click(function () { + //na +}); //import from clipboard ui.toolbar.import.clipboard.click(function () { //na @@ -1355,6 +1361,45 @@ $("#gistImportModalConfirm").click(function () { } }); +// snippet import modal +$("#snippetImportModalClear").click(function () { + $("#snippetImportModalContent").val(''); +}); +$("#snippetImportModalConfirm").click(function () { + var snippeturl = $("#snippetImportModalContent").val(); + if (!snippeturl) return; + $('#snippetImportModal').modal('hide'); + $("#snippetImportModalContent").val(''); + if (!isValidURL(snippeturl)) { + showMessageModal(' Import from Snippet', 'Not a valid URL :(', '', '', false); + return; + } else { + // TODO: Validate against config.gitlab.baseURL + ui.spinner.show(); + $.get(snippeturl) + .success(function (data) { + if (data.files) { + var contents = ""; + Object.keys(data.files).forEach(function (key) { + contents += key; + contents += '\n---\n'; + contents += data.files[key].content; + contents += '\n\n'; + }); + replaceAll(contents); + } else { + showMessageModal(' Import from Snippet', 'Unable to fetch snippet files :(', '', '', false); + } + }) + .error(function (data) { + showMessageModal(' Import from Snippet', 'Not a valid Snippet URL :(', '', JSON.stringify(data), false); + }) + .complete(function () { + ui.spinner.hide(); + }); + } +}); + function parseToEditor(data) { var parsed = toMarkdown(data); if (parsed) -- cgit v1.3.1 From 3dd3e6bc3596c0bba50dca3d1789f55883e0f681 Mon Sep 17 00:00:00 2001 From: Jason Croft Date: Wed, 11 May 2016 17:05:25 -0400 Subject: Allow importing from GitLab snippet --- public/js/index.js | 69 +++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 48 insertions(+), 21 deletions(-) (limited to 'public/js') diff --git a/public/js/index.js b/public/js/index.js index 17516169..7b22f7fa 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -243,6 +243,15 @@ var lastInfo = { }; var personalInfo = {}; var onlineUsers = []; +var fileTypes = { + "pl": "perl", + "cgi": "perl", + "js": "javascript", + "php": "php", + "sh": "bash", + "rb": "ruby", + "html": "html" +} //editor settings var textit = document.getElementById("textit"); @@ -1192,7 +1201,22 @@ ui.toolbar.import.gist.click(function () { }); //import from snippet ui.toolbar.import.snippet.click(function () { - //na + $.get(serverurl + '/gitlab') + .success(function (data) { + $("#snippetImportModalAccessToken").val(data.accesstoken); + $("#snippetImportModalBaseURL").val(data.baseURL); + $("#snippetImportModalContent").prop('disabled', false); + $("#snippetImportModalConfirm").prop('disabled', false); + $("#snippetImportModalLoading").hide(); + $("#snippetImportModal").modal('toggle'); + }) + .error(function (data) { + showMessageModal(' Import from Snippet', 'Unable to fetch gitlab parameters :(', '', '', false); + }) + .complete(function () { + //na + }); + return false; }); //import from clipboard ui.toolbar.import.clipboard.click(function () { @@ -1370,32 +1394,35 @@ $("#snippetImportModalConfirm").click(function () { if (!snippeturl) return; $('#snippetImportModal').modal('hide'); $("#snippetImportModalContent").val(''); - if (!isValidURL(snippeturl)) { - showMessageModal(' Import from Snippet', 'Not a valid URL :(', '', '', false); - return; + if (!/^.+\/snippets\/.+$/.test(snippeturl)) { + showMessageModal(' Import from Snippet', 'Not a valid Snippet URL :(', '', '', false); } else { - // TODO: Validate against config.gitlab.baseURL ui.spinner.show(); - $.get(snippeturl) - .success(function (data) { - if (data.files) { - var contents = ""; - Object.keys(data.files).forEach(function (key) { - contents += key; - contents += '\n---\n'; - contents += data.files[key].content; - contents += '\n\n'; + var accessToken = '?access_token=' + $("#snippetImportModalAccessToken").val(); + var fullURL = $("#snippetImportModalBaseURL").val() + '/api/v3' + snippeturl; + $.get(fullURL + accessToken) + .success(function(data) { + var content = '# ' + (data.title || "Snippet Import"); + var fileInfo = data.file_name.split('.'); + $.get(fullURL + '/raw' + accessToken) + .success(function (raw) { + if (raw) { + content += "\n\n```"; + content += fileTypes[fileInfo[1]] + "=\n"; + content += raw; + content += "\n```"; + replaceAll(content); + } + }) + .error(function (data) { + showMessageModal(' Import from Snippet', 'Not a valid Snippet URL :(', '', JSON.stringify(data), false); + }) + .complete(function () { + ui.spinner.hide(); }); - replaceAll(contents); - } else { - showMessageModal(' Import from Snippet', 'Unable to fetch snippet files :(', '', '', false); - } }) .error(function (data) { showMessageModal(' Import from Snippet', 'Not a valid Snippet URL :(', '', JSON.stringify(data), false); - }) - .complete(function () { - ui.spinner.hide(); }); } }); -- cgit v1.3.1 From c16345ab128288b92023e789f09cabb5197d1181 Mon Sep 17 00:00:00 2001 From: Jason Croft Date: Thu, 12 May 2016 11:19:14 -0400 Subject: Can now select from available projects and snippets to build import URL. --- app.js | 14 ++++++++++++-- public/css/index.css | 5 +++++ public/js/index.js | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ public/views/body.ejs | 20 ++++++++++++++++++-- 4 files changed, 86 insertions(+), 4 deletions(-) (limited to 'public/js') diff --git a/app.js b/app.js index 964a3a81..60eb61b5 100644 --- a/app.js +++ b/app.js @@ -448,10 +448,20 @@ app.get('/gitlab', function (req, res) { models.User.findById(req.cookies.userid) .then(function(user) { ret.accesstoken = user.accessToken; - return res.send(ret); + request( + config.gitlab.baseURL + '/api/v3/projects?access_token=' + user.accessToken, + function(error, httpResponse, body) { + if (!error && httpResponse.statusCode == 200) { + ret.projects = JSON.parse(body); + return res.send(ret); + } else { + return res.send(ret); + } + } + ); }).catch(function(err) { logger.error('user search failed: ' + err); - return done(err, null); + return response.errorInternalError(res); }); }); //get new note diff --git a/public/css/index.css b/public/css/index.css index fdfae0ac..aaf84a04 100644 --- a/public/css/index.css +++ b/public/css/index.css @@ -328,6 +328,11 @@ div[contenteditable]:empty:not(:focus):before{ border-bottom: 1px solid #ccc; } +.snippet-import-or { + text-align: center; + width: 100%; +} + .status-bar { background: #1c1c1e; border-top: 1px solid #343434; diff --git a/public/js/index.js b/public/js/index.js index 7b22f7fa..199c678e 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -552,6 +552,10 @@ var ui = { codemirrorSizer: $(".ui-edit-area .CodeMirror .CodeMirror-sizer"), codemirrorSizerInner: $(".ui-edit-area .CodeMirror .CodeMirror-sizer > div"), markdown: $(".ui-view-area .markdown-body") + }, + modal: { + snippetProjects: $("#snippetImportModalProjects"), + snippetSnippets: $("#snippetImportModalSnippets") } }; @@ -1209,6 +1213,17 @@ ui.toolbar.import.snippet.click(function () { $("#snippetImportModalConfirm").prop('disabled', false); $("#snippetImportModalLoading").hide(); $("#snippetImportModal").modal('toggle'); + $("#snippetImportModalProjects").find('option').remove().end().append('Select From Available Projects'); + if (data.projects) { + data.projects.sort(function(a,b) { + return (a.path_with_namespace < b.path_with_namespace) ? -1 : ((a.path_with_namespace > b.path_with_namespace) ? 1 : 0); + }); + data.projects.forEach(function(project) { + $('').val(project.id).text(project.path_with_namespace).appendTo("#snippetImportModalProjects"); + }); + $("#snippetImportModalProjects").prop('disabled',false); + } + $("#snippetImportModalLoading").hide(); }) .error(function (data) { showMessageModal(' Import from Snippet', 'Unable to fetch gitlab parameters :(', '', '', false); @@ -1239,6 +1254,39 @@ ui.toolbar.beta.pdf.attr("download", "").attr("href", noteurl + "/pdf"); //slide ui.toolbar.beta.slide.attr("href", noteurl + "/slide"); +//modal actions +//snippet projects +ui.modal.snippetProjects.change(function() { + var accesstoken = $("#snippetImportModalAccessToken").val(), + baseURL = $("#snippetImportModalBaseURL").val(), + project = $("#snippetImportModalProjects").val(); + + $("#snippetImportModalLoading").show(); + $("#snippetImportModalContent").val('/projects/' + project); + $.get(baseURL + '/api/v3/projects/' + project + '/snippets?access_token=' + accesstoken) + .success(function(data) { + $("#snippetImportModalSnippets").find('option').remove().end().append('Select From Available Snippets'); + data.forEach(function(snippet) { + $('').val(snippet.id).text(snippet.title).appendTo($("#snippetImportModalSnippets")); + }); + $("#snippetImportModalLoading").hide(); + $("#snippetImportModalSnippets").prop('disabled',false); + }) + .error(function(err) { + + }) + .complete(function() { + //na + }); +}); +//snippet snippets +ui.modal.snippetSnippets.change(function() { + var project = $("#snippetImportModalProjects").val(), + snippet = $("#snippetImportModalSnippets").val(); + + $("#snippetImportModalContent").val($("#snippetImportModalContent").val() + '/snippets/' + snippet); +}) + function scrollToTop() { if (currentMode == modeType.both) { if (editor.getScrollInfo().top != 0) @@ -1388,6 +1436,9 @@ $("#gistImportModalConfirm").click(function () { // snippet import modal $("#snippetImportModalClear").click(function () { $("#snippetImportModalContent").val(''); + $("#snippetImportModalProjects").val('init'); + $("#snippetImportModalSnippets").val('init'); + $("#snippetImportModalSnippets").prop('disabled',true); }); $("#snippetImportModalConfirm").click(function () { var snippeturl = $("#snippetImportModalContent").val(); diff --git a/public/views/body.ejs b/public/views/body.ejs index 039690ef..a0b872d4 100644 --- a/public/views/body.ejs +++ b/public/views/body.ejs @@ -158,14 +158,30 @@ × - Import from Snippet + Import from Snippet - + + + Project: + + Select From Available Projects + + + + Snippet + + Select From Available Snippets + + + + OR + + + + + + + × + + Export to Snippet + + + + + + + Title: + + + + File Name: + + + + Project: + + Select From Available Projects + + + + Visibility: + + Select Visibility Level + Private + Internal + + + + + + + + <%- include modal %> \ No newline at end of file diff --git a/public/views/header.ejs b/public/views/header.ejs index 051817dc..ee89ddeb 100644 --- a/public/views/header.ejs +++ b/public/views/header.ejs @@ -43,7 +43,7 @@ <% } %> <% if(typeof gitlab !== 'undefined' && gitlab) { %> - Snippet + Snippet <% } %> @@ -136,7 +136,7 @@ <% } %> <% if(typeof gitlab !== 'undefined' && gitlab) { %> - Snippet + Snippet <% } %> -- cgit v1.3.1 From ba0a8f584a0655552e3ed95cd5ef006eeb408eef Mon Sep 17 00:00:00 2001 From: Jason Croft Date: Thu, 12 May 2016 14:26:55 -0400 Subject: Filter out projects that don't have snippets enabled. --- public/js/index.js | 3 +++ 1 file changed, 3 insertions(+) (limited to 'public/js') diff --git a/public/js/index.js b/public/js/index.js index bdb9d478..fbaf95fb 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -1163,6 +1163,9 @@ ui.toolbar.export.snippet.click(function() { return (a.path_with_namespace < b.path_with_namespace) ? -1 : ((a.path_with_namespace > b.path_with_namespace) ? 1 : 0); }); data.projects.forEach(function(project) { + if (!project.snippets_enabled) { + return; + } $('').val(project.id).text(project.path_with_namespace).appendTo("#snippetExportModalProjects"); }); $("#snippetExportModalProjects").prop('disabled',false); -- cgit v1.3.1 From edcb766b63694948b91094995ca7720c1ea222c3 Mon Sep 17 00:00:00 2001 From: Jason Croft Date: Fri, 13 May 2016 10:00:34 -0400 Subject: Apply "snippets_enabled only" logic to import modal. Better parsing for snippet import. Add python filetype. --- public/js/index.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'public/js') diff --git a/public/js/index.js b/public/js/index.js index fbaf95fb..a1e0445b 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -250,8 +250,9 @@ var fileTypes = { "php": "php", "sh": "bash", "rb": "ruby", - "html": "html" -} + "html": "html", + "py": "python" +}; //editor settings var textit = document.getElementById("textit"); @@ -1248,6 +1249,9 @@ ui.toolbar.import.snippet.click(function () { return (a.path_with_namespace < b.path_with_namespace) ? -1 : ((a.path_with_namespace > b.path_with_namespace) ? 1 : 0); }); data.projects.forEach(function(project) { + if (!project.snippets_enabled) { + return; + } $('').val(project.id).text(project.path_with_namespace).appendTo("#snippetImportModalProjects"); }); $("#snippetImportModalProjects").prop('disabled',false); @@ -1484,13 +1488,18 @@ $("#snippetImportModalConfirm").click(function () { .success(function(data) { var content = '# ' + (data.title || "Snippet Import"); var fileInfo = data.file_name.split('.'); + fileInfo[1] = (fileInfo[1]) ? fileInfo[1] : "md"; $.get(fullURL + '/raw' + accessToken) .success(function (raw) { if (raw) { - content += "\n\n```"; - content += fileTypes[fileInfo[1]] + "=\n"; + content += "\n\n"; + if (fileInfo[1] != "md") { + content += "```" + fileTypes[fileInfo[1]] + "\n"; + } content += raw; - content += "\n```"; + if (fileInfo[1] != "md") { + content += "\n```"; + } replaceAll(content); } }) -- cgit v1.3.1 From 930afdc33738a487bd9e596c5d35bc9f686eaaa1 Mon Sep 17 00:00:00 2001 From: Jason Croft Date: Fri, 13 May 2016 10:32:30 -0400 Subject: Show only projects where user is creator, has project access >= 20, or has group access. --- app.js | 1 + public/js/index.js | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) (limited to 'public/js') diff --git a/app.js b/app.js index 5d847f76..35408bb0 100644 --- a/app.js +++ b/app.js @@ -448,6 +448,7 @@ app.get('/gitlab', function (req, res) { models.User.findById(req.cookies.userid) .then(function(user) { ret.accesstoken = user.accessToken; + ret.profileid = user.profileid; request( config.gitlab.baseURL + '/api/v3/projects?access_token=' + user.accessToken, function(error, httpResponse, body) { diff --git a/public/js/index.js b/public/js/index.js index a1e0445b..7e692bee 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -1164,7 +1164,10 @@ ui.toolbar.export.snippet.click(function() { return (a.path_with_namespace < b.path_with_namespace) ? -1 : ((a.path_with_namespace > b.path_with_namespace) ? 1 : 0); }); data.projects.forEach(function(project) { - if (!project.snippets_enabled) { + if (!project.snippets_enabled + || (project.permissions.project_access === null && project.permissions.group_access === null) + || (project.permissions.project_access !== null && project.permissions.project_access.access_level < 20)) + { return; } $('').val(project.id).text(project.path_with_namespace).appendTo("#snippetExportModalProjects"); @@ -1249,7 +1252,10 @@ ui.toolbar.import.snippet.click(function () { return (a.path_with_namespace < b.path_with_namespace) ? -1 : ((a.path_with_namespace > b.path_with_namespace) ? 1 : 0); }); data.projects.forEach(function(project) { - if (!project.snippets_enabled) { + if (!project.snippets_enabled + || (project.permissions.project_access === null && project.permissions.group_access === null) + || (project.permissions.project_access !== null && project.permissions.project_access.access_level < 20)) + { return; } $('').val(project.id).text(project.path_with_namespace).appendTo("#snippetImportModalProjects"); -- cgit v1.3.1
OR