Can now select from available projects and snippets to build import URL.

This commit is contained in:
Jason Croft 2016-05-12 11:19:14 -04:00
parent de998c4a0f
commit c16345ab12
4 changed files with 86 additions and 4 deletions

14
app.js
View file

@ -448,10 +448,20 @@ app.get('/gitlab', function (req, res) {
models.User.findById(req.cookies.userid) models.User.findById(req.cookies.userid)
.then(function(user) { .then(function(user) {
ret.accesstoken = user.accessToken; 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) { }).catch(function(err) {
logger.error('user search failed: ' + err); logger.error('user search failed: ' + err);
return done(err, null); return response.errorInternalError(res);
}); });
}); });
//get new note //get new note

View file

@ -328,6 +328,11 @@ div[contenteditable]:empty:not(:focus):before{
border-bottom: 1px solid #ccc; border-bottom: 1px solid #ccc;
} }
.snippet-import-or {
text-align: center;
width: 100%;
}
.status-bar { .status-bar {
background: #1c1c1e; background: #1c1c1e;
border-top: 1px solid #343434; border-top: 1px solid #343434;

View file

@ -552,6 +552,10 @@ var ui = {
codemirrorSizer: $(".ui-edit-area .CodeMirror .CodeMirror-sizer"), codemirrorSizer: $(".ui-edit-area .CodeMirror .CodeMirror-sizer"),
codemirrorSizerInner: $(".ui-edit-area .CodeMirror .CodeMirror-sizer > div"), codemirrorSizerInner: $(".ui-edit-area .CodeMirror .CodeMirror-sizer > div"),
markdown: $(".ui-view-area .markdown-body") 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); $("#snippetImportModalConfirm").prop('disabled', false);
$("#snippetImportModalLoading").hide(); $("#snippetImportModalLoading").hide();
$("#snippetImportModal").modal('toggle'); $("#snippetImportModal").modal('toggle');
$("#snippetImportModalProjects").find('option').remove().end().append('<option value="init" selected="selected" disabled="disabled">Select From Available Projects</option>');
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) {
$('<option>').val(project.id).text(project.path_with_namespace).appendTo("#snippetImportModalProjects");
});
$("#snippetImportModalProjects").prop('disabled',false);
}
$("#snippetImportModalLoading").hide();
}) })
.error(function (data) { .error(function (data) {
showMessageModal('<i class="fa fa-gitlab"></i> Import from Snippet', 'Unable to fetch gitlab parameters :(', '', '', false); showMessageModal('<i class="fa fa-gitlab"></i> Import from Snippet', 'Unable to fetch gitlab parameters :(', '', '', false);
@ -1239,6 +1254,39 @@ ui.toolbar.beta.pdf.attr("download", "").attr("href", noteurl + "/pdf");
//slide //slide
ui.toolbar.beta.slide.attr("href", noteurl + "/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('<option value="init" selected="selected" disabled="disabled">Select From Available Snippets</option>');
data.forEach(function(snippet) {
$('<option>').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() { function scrollToTop() {
if (currentMode == modeType.both) { if (currentMode == modeType.both) {
if (editor.getScrollInfo().top != 0) if (editor.getScrollInfo().top != 0)
@ -1388,6 +1436,9 @@ $("#gistImportModalConfirm").click(function () {
// snippet import modal // snippet import modal
$("#snippetImportModalClear").click(function () { $("#snippetImportModalClear").click(function () {
$("#snippetImportModalContent").val(''); $("#snippetImportModalContent").val('');
$("#snippetImportModalProjects").val('init');
$("#snippetImportModalSnippets").val('init');
$("#snippetImportModalSnippets").prop('disabled',true);
}); });
$("#snippetImportModalConfirm").click(function () { $("#snippetImportModalConfirm").click(function () {
var snippeturl = $("#snippetImportModalContent").val(); var snippeturl = $("#snippetImportModalContent").val();

View file

@ -158,14 +158,30 @@
<div class="modal-header"> <div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span> <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
</button> </button>
<h4 class="modal-title" id="myModalLabel">Import from Snippet <i class="fa fa-refresh fa-spin" id="snippetImportModalLoading"></i></h4> <h4 class="modal-title" id="myModalLabel">Import from Snippet</h4>
</div> </div>
<div class="modal-body"> <div class="modal-body">
<input type="hidden" id="snippetImportModalAccessToken" /> <input type="hidden" id="snippetImportModalAccessToken" />
<input type="hidden" id="snippetImportModalBaseURL" /> <input type="hidden" id="snippetImportModalBaseURL" />
<input type="url" class="form-control" placeholder="Paste your snippet url here... (like: /projects/:id/snippets/:snippet_id)" id="snippetImportModalContent" disabled="disabled"> <div class="ui-field-contain" style="display:table;margin-bottom:10px;width:100%;">
<div style="display:table-row;margin-bottom:5px;">
<label style="display:table-cell;">Project:</label>
<select class="form-control" id="snippetImportModalProjects" style="display:table-cell;" disabled="disabled">
<option value="init" selected="selected" disabled="disabled">Select From Available Projects</option>
</select>
</div>
<div style="display:table-row;">
<label style="display:table-cell;">Snippet</label>
<select class="form-control" id="snippetImportModalSnippets" style="display:table-cell;" disabled="disabled">
<option value="init" selected="selected" disabled="disabled">Select From Available Snippets</option>
</select>
</div>
</div>
<p class="snippet-import-or">OR</p>
<input type="url" class="form-control" placeholder="/projects/:id/snippets/:snippet_id" id="snippetImportModalContent" disabled="disabled">
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<span id="snippetImportModalLoading"><i class="fa fa-refresh fa-spin"></i></span>
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button> <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-danger" id="snippetImportModalClear">Clear</button> <button type="button" class="btn btn-danger" id="snippetImportModalClear">Clear</button>
<button type="button" class="btn btn-primary" id="snippetImportModalConfirm" disabled="disabled">Import</button> <button type="button" class="btn btn-primary" id="snippetImportModalConfirm" disabled="disabled">Import</button>