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(-) 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 +
OR