From 30e602a7400f3b38918a55f1470610b8d4ee49d7 Mon Sep 17 00:00:00 2001 From: Jason Croft Date: Thu, 12 May 2016 12:28:08 -0400 Subject: Enable snippet exporting. --- public/js/index.js | 61 +++++++++++++++++++++++++++++++++++++++++++++---- public/views/body.ejs | 45 ++++++++++++++++++++++++++++++++++++ public/views/header.ejs | 4 ++-- 3 files changed, 103 insertions(+), 7 deletions(-) diff --git a/public/js/index.js b/public/js/index.js index 199c678e..bdb9d478 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -554,8 +554,8 @@ var ui = { markdown: $(".ui-view-area .markdown-body") }, modal: { - snippetProjects: $("#snippetImportModalProjects"), - snippetSnippets: $("#snippetImportModalSnippets") + snippetImportProjects: $("#snippetImportModalProjects"), + snippetImportSnippets: $("#snippetImportModalSnippets") } }; @@ -1150,7 +1150,33 @@ 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"); +ui.toolbar.export.snippet.click(function() { + $.get(serverurl + '/gitlab') + .success(function (data) { + $("#snippetExportModalAccessToken").val(data.accesstoken); + $("#snippetExportModalBaseURL").val(data.baseURL); + $("#snippetExportModalLoading").hide(); + $("#snippetExportModal").modal('toggle'); + $("#snippetExportModalProjects").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("#snippetExportModalProjects"); + }); + $("#snippetExportModalProjects").prop('disabled',false); + } + $("#snippetExportModalLoading").hide(); + }) + .error(function (data) { + showMessageModal(' Import from Snippet', 'Unable to fetch gitlab parameters :(', '', '', false); + }) + .complete(function () { + //na + }); + return false; +}); //import from dropbox ui.toolbar.import.dropbox.click(function () { var options = { @@ -1256,7 +1282,7 @@ ui.toolbar.beta.slide.attr("href", noteurl + "/slide"); //modal actions //snippet projects -ui.modal.snippetProjects.change(function() { +ui.modal.snippetImportProjects.change(function() { var accesstoken = $("#snippetImportModalAccessToken").val(), baseURL = $("#snippetImportModalBaseURL").val(), project = $("#snippetImportModalProjects").val(); @@ -1280,7 +1306,7 @@ ui.modal.snippetProjects.change(function() { }); }); //snippet snippets -ui.modal.snippetSnippets.change(function() { +ui.modal.snippetImportSnippets.change(function() { var project = $("#snippetImportModalProjects").val(), snippet = $("#snippetImportModalSnippets").val(); @@ -1478,6 +1504,31 @@ $("#snippetImportModalConfirm").click(function () { } }); +//snippet export modal +$("#snippetExportModalConfirm").click(function() { + var accesstoken = $("#snippetExportModalAccessToken").val(), + baseURL = $("#snippetExportModalBaseURL").val(), + data = { + title: $("#snippetExportModalTitle").val(), + file_name: $("#snippetExportModalFileName").val(), + code: editor.getValue(), + visibility_level: $("#snippetExportModalVisibility").val() + }; + + $("#snippetExportModalLoading").show(); + var fullURL = baseURL + '/api/v3/projects/' + $("#snippetExportModalProjects").val() + '/snippets?access_token=' + accesstoken; + $.post(fullURL + , data + , function(ret) { + $("#snippetExportModalLoading").hide(); + $('#snippetExportModal').modal('hide'); + var redirect = baseURL + '/' + $("#snippetExportModalProjects option[value='" + $("#snippetExportModalProjects").val() + "']").text() + '/snippets/' + ret.id; + showMessageModal(' Export to Snippet', 'Export Successful!', redirect, 'View Snippet Here', true); + } + , 'json' + ); +}); + function parseToEditor(data) { var parsed = toMarkdown(data); if (parsed) diff --git a/public/views/body.ejs b/public/views/body.ejs index a0b872d4..f0b62c28 100644 --- a/public/views/body.ejs +++ b/public/views/body.ejs @@ -189,4 +189,49 @@ + + + + + + × + + 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.2.3