From c16345ab128288b92023e789f09cabb5197d1181 Mon Sep 17 00:00:00 2001 From: Jason Croft Date: Thu, 12 May 2016 11:19:14 -0400 Subject: [PATCH] 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 964a3a810..60eb61b59 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 fdfae0ac8..aaf84a041 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 7b22f7faf..199c678e9 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(''); + 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) { + $(''); + data.forEach(function(snippet) { + $('