mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-08-07 23:03:00 +03:00
Merge branch 'master' of https://github.com/Abijeet/BookStack
Conflicts: .gitignore
This commit is contained in:
@@ -305,6 +305,7 @@ export default function (ngApp, events) {
|
||||
$scope.draftsEnabled = $attrs.draftsEnabled === 'true';
|
||||
$scope.isUpdateDraft = Number($attrs.pageUpdateDraft) === 1;
|
||||
$scope.isNewPageDraft = Number($attrs.pageNewDraft) === 1;
|
||||
$scope.commentsLoaded = false;
|
||||
|
||||
// Set initial header draft text
|
||||
if ($scope.isUpdateDraft || $scope.isNewPageDraft) {
|
||||
@@ -714,4 +715,79 @@ export default function (ngApp, events) {
|
||||
|
||||
}]);
|
||||
|
||||
// CommentCrudController
|
||||
ngApp.controller('CommentAddController', ['$scope', '$http', function ($scope, $http) {
|
||||
let vm = this;
|
||||
let comment = {};
|
||||
$scope.errors = {};
|
||||
vm.saveComment = function () {
|
||||
let pageId = $scope.comment.pageId;
|
||||
let comment = $scope.comment.newComment;
|
||||
let commentHTML = $scope.getCommentHTML();
|
||||
|
||||
$http.post(window.baseUrl(`/ajax/page/${pageId}/comment/`), {
|
||||
text: comment,
|
||||
html: commentHTML
|
||||
}).then(resp => {
|
||||
$scope.clearInput();
|
||||
if (!resp.data || resp.data.status !== 'success') {
|
||||
return events.emit('error', trans('error'));
|
||||
}
|
||||
events.emit('success', trans(resp.data.message));
|
||||
}, checkError('add'));
|
||||
|
||||
};
|
||||
|
||||
function checkError(errorGroupName) {
|
||||
$scope.errors[errorGroupName] = {};
|
||||
return function(response) {
|
||||
if (typeof response.data !== 'undefined' && typeof response.data.error !== 'undefined') {
|
||||
events.emit('error', response.data.error);
|
||||
}
|
||||
if (typeof response.data !== 'undefined' && typeof response.data.validation !== 'undefined') {
|
||||
$scope.errors[errorGroupName] = response.data.validation;
|
||||
console.log($scope.errors[errorGroupName])
|
||||
}
|
||||
}
|
||||
}
|
||||
}]);
|
||||
|
||||
|
||||
// CommentListController
|
||||
ngApp.controller('CommentListController', ['$scope', '$http', '$timeout', function ($scope, $http, $timeout) {
|
||||
let vm = this;
|
||||
$scope.errors = {};
|
||||
$scope.defaultAvatar = defaultAvatar;
|
||||
vm.totalCommentsStr = 'Loading...';
|
||||
$scope.editorChange = function (content) {
|
||||
console.log(content);
|
||||
}
|
||||
|
||||
$timeout(function() {
|
||||
console.log($scope.pageId);
|
||||
$http.get(window.baseUrl(`/ajax/page/${$scope.pageId}/comments/`)).then(resp => {
|
||||
if (!resp.data || resp.data.success !== true) {
|
||||
// TODO : Handle error
|
||||
return;
|
||||
}
|
||||
vm.comments = resp.data.comments.data;
|
||||
vm.totalComments = resp.data.comments.total;
|
||||
if (vm.totalComments === 0) {
|
||||
vm.totalCommentsStr = 'No comments found.';
|
||||
} else if (vm.totalComments === 1) {
|
||||
vm.totalCommentsStr = '1 Comments';
|
||||
} else {
|
||||
vm.totalCommentsStr = vm.totalComments + ' Comments'
|
||||
}
|
||||
}, checkError('app'));
|
||||
});
|
||||
|
||||
function checkError(errorGroupName) {
|
||||
$scope.errors[errorGroupName] = {};
|
||||
return function(response) {
|
||||
console.log(resp);
|
||||
}
|
||||
}
|
||||
}]);
|
||||
|
||||
};
|
||||
|
@@ -214,6 +214,19 @@ export default function (ngApp, events) {
|
||||
}
|
||||
}]);
|
||||
|
||||
let renderer = new markdown.Renderer();
|
||||
// Custom markdown checkbox list item
|
||||
// Attribution: https://github.com/chjj/marked/issues/107#issuecomment-44542001
|
||||
renderer.listitem = function(text) {
|
||||
if (/^\s*\[[x ]\]\s*/.test(text)) {
|
||||
text = text
|
||||
.replace(/^\s*\[ \]\s*/, '<input type="checkbox"/>')
|
||||
.replace(/^\s*\[x\]\s*/, '<input type="checkbox" checked/>');
|
||||
return `<li class="checkbox-item">${text}</li>`;
|
||||
}
|
||||
return `<li>${text}</li>`;
|
||||
};
|
||||
|
||||
/**
|
||||
* Markdown input
|
||||
* Handles the logic for just the editor input field.
|
||||
@@ -231,13 +244,13 @@ export default function (ngApp, events) {
|
||||
element = element.find('textarea').first();
|
||||
let content = element.val();
|
||||
scope.mdModel = content;
|
||||
scope.mdChange(markdown(content));
|
||||
scope.mdChange(markdown(content, {renderer: renderer}));
|
||||
|
||||
element.on('change input', (event) => {
|
||||
content = element.val();
|
||||
$timeout(() => {
|
||||
scope.mdModel = content;
|
||||
scope.mdChange(markdown(content));
|
||||
scope.mdChange(markdown(content, {renderer: renderer}));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -814,4 +827,52 @@ export default function (ngApp, events) {
|
||||
}
|
||||
};
|
||||
}]);
|
||||
|
||||
|
||||
ngApp.directive('simpleMarkdownInput', ['$timeout', function ($timeout) {
|
||||
return {
|
||||
restrict: 'A',
|
||||
scope: {
|
||||
smdModel: '=',
|
||||
smdChange: '=',
|
||||
smdGetContent: '=',
|
||||
smdClear: '='
|
||||
},
|
||||
link: function (scope, element, attrs) {
|
||||
// Set initial model content
|
||||
element = element.find('textarea').first();
|
||||
let simplemde = new SimpleMDE({
|
||||
element: element[0],
|
||||
status: []
|
||||
});
|
||||
let content = element.val();
|
||||
simplemde.value(content)
|
||||
scope.smdModel = content;
|
||||
|
||||
simplemde.codemirror.on('change', (event) => {
|
||||
content = simplemde.value();
|
||||
$timeout(() => {
|
||||
scope.smdModel = content;
|
||||
if (scope.smdChange) {
|
||||
scope.smdChange(element, content);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
if ('smdGetContent' in attrs) {
|
||||
scope.smdGetContent = function () {
|
||||
return simplemde.options.previewRender(simplemde.value());
|
||||
};
|
||||
}
|
||||
|
||||
if ('smdClear' in attrs) {
|
||||
scope.smdClear = function () {
|
||||
simplemde.value('');
|
||||
scope.smdModel = '';
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}]);
|
||||
|
||||
};
|
||||
|
Reference in New Issue
Block a user