Custom commit message available. Improved history viewer and feedback from revert buttons.
This commit is contained in:
parent
08a9553ccc
commit
b8b50bdb5a
@ -29,6 +29,7 @@ class Wiki extends \Zotlabs\Web\Controller {
|
|||||||
// Something like $interface = array('new_page_button' => false, 'new_wiki_button' => false, ...)
|
// Something like $interface = array('new_page_button' => false, 'new_wiki_button' => false, ...)
|
||||||
$wiki_owner = false;
|
$wiki_owner = false;
|
||||||
$showNewWikiButton = false;
|
$showNewWikiButton = false;
|
||||||
|
$showCommitMsg = false;
|
||||||
$pageHistory = array();
|
$pageHistory = array();
|
||||||
$local_observer = null;
|
$local_observer = null;
|
||||||
$resource_id = '';
|
$resource_id = '';
|
||||||
@ -77,6 +78,7 @@ class Wiki extends \Zotlabs\Web\Controller {
|
|||||||
$showPageControls = false;
|
$showPageControls = false;
|
||||||
$showNewWikiButton = $wiki_owner;
|
$showNewWikiButton = $wiki_owner;
|
||||||
$showNewPageButton = false;
|
$showNewPageButton = false;
|
||||||
|
$showCommitMsg = false;
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
// /wiki/channel/wiki -> No page was specified, so redirect to Home.md
|
// /wiki/channel/wiki -> No page was specified, so redirect to Home.md
|
||||||
@ -114,6 +116,7 @@ class Wiki extends \Zotlabs\Web\Controller {
|
|||||||
$showPageControls = $wiki_owner;
|
$showPageControls = $wiki_owner;
|
||||||
$showNewWikiButton = $wiki_owner;
|
$showNewWikiButton = $wiki_owner;
|
||||||
$showNewPageButton = $wiki_owner;
|
$showNewPageButton = $wiki_owner;
|
||||||
|
$showCommitMsg = true;
|
||||||
$pageHistory = wiki_page_history(array('resource_id' => $resource_id, 'pageUrlName' => $pageUrlName));
|
$pageHistory = wiki_page_history(array('resource_id' => $resource_id, 'pageUrlName' => $pageUrlName));
|
||||||
break;
|
break;
|
||||||
default: // Strip the extraneous URL components
|
default: // Strip the extraneous URL components
|
||||||
@ -128,6 +131,7 @@ class Wiki extends \Zotlabs\Web\Controller {
|
|||||||
'$showPageControls' => $showPageControls,
|
'$showPageControls' => $showPageControls,
|
||||||
'$showNewWikiButton'=> $showNewWikiButton,
|
'$showNewWikiButton'=> $showNewWikiButton,
|
||||||
'$showNewPageButton'=> $showNewPageButton,
|
'$showNewPageButton'=> $showNewPageButton,
|
||||||
|
'$showCommitMsg' => $showCommitMsg,
|
||||||
'$channel' => $channel['channel_address'],
|
'$channel' => $channel['channel_address'],
|
||||||
'$resource_id' => $resource_id,
|
'$resource_id' => $resource_id,
|
||||||
'$page' => $pageUrlName,
|
'$page' => $pageUrlName,
|
||||||
@ -138,6 +142,7 @@ class Wiki extends \Zotlabs\Web\Controller {
|
|||||||
'$renderedContent' => Markdown(json_decode($content)),
|
'$renderedContent' => Markdown(json_decode($content)),
|
||||||
'$wikiName' => array('wikiName', t('Enter the name of your new wiki:'), '', ''),
|
'$wikiName' => array('wikiName', t('Enter the name of your new wiki:'), '', ''),
|
||||||
'$pageName' => array('pageName', t('Enter the name of the new page:'), '', ''),
|
'$pageName' => array('pageName', t('Enter the name of the new page:'), '', ''),
|
||||||
|
'$commitMsg' => array('commitMsg', '', '', '', '', 'placeholder="(optional) Enter a custom message when saving the page..."'),
|
||||||
'$pageHistory' => $pageHistory['history']
|
'$pageHistory' => $pageHistory['history']
|
||||||
));
|
));
|
||||||
head_add_js('library/ace/ace.js'); // Ace Code Editor
|
head_add_js('library/ace/ace.js'); // Ace Code Editor
|
||||||
@ -290,6 +295,10 @@ class Wiki extends \Zotlabs\Web\Controller {
|
|||||||
$pageUrlName = $_POST['name'];
|
$pageUrlName = $_POST['name'];
|
||||||
$pageHtmlName = escape_tags($_POST['name']);
|
$pageHtmlName = escape_tags($_POST['name']);
|
||||||
$content = escape_tags($_POST['content']); //Get new content
|
$content = escape_tags($_POST['content']); //Get new content
|
||||||
|
$commitMsg = $_POST['commitMsg'];
|
||||||
|
if ($commitMsg === '') {
|
||||||
|
$commitMsg = 'Updated ' . $pageHtmlName;
|
||||||
|
}
|
||||||
// Determine if observer has permission to save content
|
// Determine if observer has permission to save content
|
||||||
if (local_channel()) {
|
if (local_channel()) {
|
||||||
$channel = \App::get_channel();
|
$channel = \App::get_channel();
|
||||||
@ -314,7 +323,7 @@ class Wiki extends \Zotlabs\Web\Controller {
|
|||||||
if($saved['success']) {
|
if($saved['success']) {
|
||||||
$ob = \App::get_observer();
|
$ob = \App::get_observer();
|
||||||
$commit = wiki_git_commit(array(
|
$commit = wiki_git_commit(array(
|
||||||
'commit_msg' => 'Updated ' . $pageHtmlName,
|
'commit_msg' => $commitMsg,
|
||||||
'resource_id' => $resource_id,
|
'resource_id' => $resource_id,
|
||||||
'observer' => $ob,
|
'observer' => $ob,
|
||||||
'files' => array($pageUrlName.'.md')
|
'files' => array($pageUrlName.'.md')
|
||||||
|
@ -101,6 +101,11 @@
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{{if $showCommitMsg}}
|
||||||
|
<div class="section-content-wrapper">
|
||||||
|
{{include file="field_input.tpl" field=$commitMsg}}
|
||||||
|
</div>
|
||||||
|
{{/if}}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
@ -198,10 +203,16 @@ function wiki_delete_wiki(wikiHtmlName, resource_id) {
|
|||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$.post("wiki/{{$channel}}/save/page", {content: editor.getValue(), name: window.wiki_page_name, resource_id: window.wiki_resource_id},
|
$.post("wiki/{{$channel}}/save/page",
|
||||||
|
{ content: editor.getValue(),
|
||||||
|
commitMsg: $('#id_commitMsg').val(),
|
||||||
|
name: window.wiki_page_name,
|
||||||
|
resource_id: window.wiki_resource_id
|
||||||
|
},
|
||||||
function (data) {
|
function (data) {
|
||||||
if (data.success) {
|
if (data.success) {
|
||||||
window.console.log('Page saved successfully.');
|
window.console.log('Page saved successfully.');
|
||||||
|
$('#id_commitMsg').val(''); // Clear the commit message box
|
||||||
} else {
|
} else {
|
||||||
alert('Error saving page.'); // TODO: Replace alerts with auto-timeout popups
|
alert('Error saving page.'); // TODO: Replace alerts with auto-timeout popups
|
||||||
window.console.log('Error saving page.');
|
window.console.log('Error saving page.');
|
||||||
@ -241,7 +252,12 @@ function wiki_delete_wiki(wikiHtmlName, resource_id) {
|
|||||||
$.post("wiki/{{$channel}}/revert/page", {commitHash: commitHash, name: window.wiki_page_name, resource_id: window.wiki_resource_id},
|
$.post("wiki/{{$channel}}/revert/page", {commitHash: commitHash, name: window.wiki_page_name, resource_id: window.wiki_resource_id},
|
||||||
function (data) {
|
function (data) {
|
||||||
if (data.success) {
|
if (data.success) {
|
||||||
window.console.log('Reverted content: ' + data.content);
|
$('button[id^=revert-]').removeClass('btn-success');
|
||||||
|
$('button[id^=revert-]').addClass('btn-danger');
|
||||||
|
$('button[id^=revert-]').html('Revert');
|
||||||
|
$('#revert-'+commitHash).removeClass('btn-danger');
|
||||||
|
$('#revert-'+commitHash).addClass('btn-success');
|
||||||
|
$('#revert-'+commitHash).html('Page reverted<br>but not saved');
|
||||||
// put contents in editor
|
// put contents in editor
|
||||||
editor.getSession().setValue(data.content);
|
editor.getSession().setValue(data.content);
|
||||||
} else {
|
} else {
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
<table class="table-striped table-responsive table-hover" style="width: 100%;">
|
<table class="table-striped table-responsive table-hover" style="width: 100%;">
|
||||||
{{foreach $pageHistory as $commit}}
|
{{foreach $pageHistory as $commit}}
|
||||||
<tr><td>
|
<tr><td>
|
||||||
<table id="rev-{{$commit.hash}}" onclick="$('#details-{{$commit.hash}}').show()">
|
<table id="rev-{{$commit.hash}}" onclick="$('#details-{{$commit.hash}}').show()" width="100%">
|
||||||
<tr><td>Date</td><td>{{$commit.date}}</td><td rowspan="3"">
|
<tr><td width="10%">Date</td><td width="70%">{{$commit.date}}</td><td rowspan="3" width="20%" align="right">
|
||||||
<button id="revert-{{$commit.hash}}" class="btn btn-warning btn-xs" onclick="wiki_revert_page('{{$commit.hash}}')">Revert</button></td></tr>
|
<button id="revert-{{$commit.hash}}" class="btn btn-danger btn-xs" onclick="wiki_revert_page('{{$commit.hash}}')">Revert</button></td></tr>
|
||||||
<tr><td>Name</td><td>{{$commit.name}}</td></tr>
|
<tr><td>Name</td><td>{{$commit.name}} <{{$commit.email}}></td></tr>
|
||||||
<tr><td>Message</td><td>{{$commit.title}}</td></tr>
|
<tr><td>Message</td><td>{{$commit.title}}</td></tr>
|
||||||
</table>
|
</table>
|
||||||
</td></tr>
|
</td></tr>
|
||||||
|
Reference in New Issue
Block a user