Wiki navigation bar
This commit is contained in:
parent
9c6114cf86
commit
4807b7d4ae
10
README.md
10
README.md
@ -1,6 +1,16 @@
|
||||
# My Wiki
|
||||
Place this app in **nextcloud/apps/**
|
||||
|
||||
|
||||
## Disclaimer:
|
||||
**This is not a real wiki**
|
||||
This app allow me to display the folders where I organize some documentation within a browsable struture
|
||||
Many things could be wrong (this is my first app for nextcloud), I would appreciate any comments/help
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## Building the app
|
||||
|
||||
The app can be built by using the provided Makefile by running:
|
||||
|
@ -1,3 +1,23 @@
|
||||
#hello {
|
||||
color: red;
|
||||
}
|
||||
|
||||
li[data-id="wikis"] select {
|
||||
width: calc(100% - 50px);
|
||||
}
|
||||
|
||||
.-myWikiControls {
|
||||
width: 100%;
|
||||
margin: .25em;
|
||||
}
|
||||
.-myWikiControls select {
|
||||
width: 98%;
|
||||
}
|
||||
|
||||
option.separator {
|
||||
font-size: 1px;
|
||||
min-height:1px;
|
||||
max-height:1px;
|
||||
padding:0;
|
||||
background-color: #000000;
|
||||
}
|
||||
|
54
js/script.js
54
js/script.js
@ -1,10 +1,55 @@
|
||||
const appName = 'MyWiki';
|
||||
|
||||
class WikiPages {
|
||||
constructor(container){
|
||||
this.wikiId = null;
|
||||
}
|
||||
load(wikiId) {
|
||||
console.info('JDG :: Loading wiki', wikiId );
|
||||
this.wikiId = wikiId;
|
||||
}
|
||||
getWikiId() {
|
||||
return this.wikiId;
|
||||
}
|
||||
add(parentPageId, title) {
|
||||
|
||||
}
|
||||
delete() {
|
||||
|
||||
}
|
||||
rename() {
|
||||
|
||||
}
|
||||
}
|
||||
class WikiEditor {
|
||||
load(wikiId, wikiPageId) {
|
||||
console.info(`JDG :: Loading Wiki ${wikiId}/${wikiPageId}`);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
var MyWiki = MyWiki || {};
|
||||
|
||||
(function(window, $, exports, undefined) {
|
||||
'use strict';
|
||||
|
||||
$('#MyWiki-test').on('click',test);
|
||||
let wikiNavigation = new WikiNavigation(document.querySelector('li[data-id="wikis"]'), onSelectWiki);
|
||||
let wikiPages = new WikiPages(document.querySelector('li[data-id="pages"]'), onSelectWikiPage);
|
||||
function onSelectWiki(wikiId) {
|
||||
console.info(`JDG :: WikiList selected ${wikiId}` );
|
||||
if ( wikiId > 0 ) {
|
||||
wikiPages.load(wikiId);
|
||||
}
|
||||
}
|
||||
function onSelectWikiPage(wikiPageId) {
|
||||
console.info(`JDG :: WikiPage selected ${wikiPageId}` );
|
||||
if ( wikiPageId > 0 ) {
|
||||
// wikiEditor.load(wikiPage.getWikiId(), wikiPageId );
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------
|
||||
$(`#${appName}-test`).on('click',test);
|
||||
function test() {
|
||||
var baseUrl = OC.generateUrl('/apps/mywiki/wikis');
|
||||
$.ajax({
|
||||
@ -19,13 +64,8 @@ var MyWiki = MyWiki || {};
|
||||
$('output').html('<h2>'+response.statusText+'</h2><code>'+response.responseText+'</code>');
|
||||
});
|
||||
}
|
||||
// ---------------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
// if this function or object should be global, attach it to the namespace
|
||||
exports.myGlobalFunction = function(params) {
|
||||
return params;
|
||||
};
|
||||
*/
|
||||
})(window, jQuery, MyWiki);
|
||||
|
||||
|
||||
|
@ -51,12 +51,12 @@
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
*
|
||||
* @param string $folderPath
|
||||
* @param string $title
|
||||
* @param string $fileId
|
||||
*/
|
||||
public function create(string $title, int $fileId) {
|
||||
return $this->handleReadOnly(function () use ($title, $fileId) {
|
||||
return $this->service->create($title, $fileId, $this->userId);
|
||||
public function create(string $folderPath, string $title) {
|
||||
return $this->handleReadOnly(function () use ($folderPath, $title) {
|
||||
return $this->service->create($folderPath, $title, $this->userId);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,7 @@ class Wiki extends Entity implements JsonSerializable {
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'title' => $this->title,
|
||||
'file_id' => $this->file_id
|
||||
'fileId' => $this->fileId
|
||||
];
|
||||
}
|
||||
}
|
@ -7,7 +7,7 @@ use OCP\AppFramework\Db\QBMapper;
|
||||
class WikiMapper extends QBMapper {
|
||||
|
||||
public function __construct(IDBConnection $db) {
|
||||
parent::__construct($db, 'mywiki_wikis', Note::class);
|
||||
parent::__construct($db, 'mywiki', Wiki::class);
|
||||
}
|
||||
|
||||
public function usersCount(int $folderId) {
|
||||
@ -31,11 +31,10 @@ class WikiMapper extends QBMapper {
|
||||
)->andWhere(
|
||||
$qb->expr()->eq('user_id', $qb->createNamedParameter($userId))
|
||||
);
|
||||
|
||||
return $this->findEntity($qb);
|
||||
}
|
||||
|
||||
public function findAll(string $userId) {
|
||||
public function findAll(string $userId, mixed $filter=null) {
|
||||
$qb = $this->db->getQueryBuilder();
|
||||
|
||||
$qb->select('*')
|
||||
@ -44,6 +43,18 @@ class WikiMapper extends QBMapper {
|
||||
$qb->expr()->eq('user_id', $qb->createNamedParameter($userId))
|
||||
);
|
||||
|
||||
if ($filter) {
|
||||
if (array_key_exists('title',$filter) ) {
|
||||
$qb->where(
|
||||
$qb->expr()->eq('title', $qb->createNamedParameter($id))
|
||||
);
|
||||
}
|
||||
if (array_key_exists('fileId',$filter) ) {
|
||||
$qb->where(
|
||||
$qb->expr()->eq('fileId', $qb->createNamedParameter($id))
|
||||
);
|
||||
}
|
||||
}
|
||||
return $this->findEntities($qb);
|
||||
}
|
||||
|
||||
|
@ -96,16 +96,24 @@ class WikiHelper {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function initWiki(string $title) :bool {
|
||||
public function initWiki(string $folderPath, string $title) :?int {
|
||||
$this->wikiFolder = $this->userFolder->get($folderPath);
|
||||
if ( !$this->isWiki() ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$folderId = $this->wikiFolder->getId();
|
||||
if ( $this->getWikiData() === null ) {
|
||||
$wiki = [
|
||||
"title"=>$title,
|
||||
"folderId"=>$this->wikiFolder->getId(),
|
||||
"folderId"=>$folderId,
|
||||
"pages"=>$this->rebuildWikiTree()
|
||||
];
|
||||
if ( $this->getWikiData() === null ) {
|
||||
return $this->setWikiData($wiki);
|
||||
if ( !$this->setWikiData($wiki) ) {
|
||||
return null;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return $folderId;
|
||||
}
|
||||
|
||||
public function add(int $parentId, string $title) {
|
||||
|
@ -39,6 +39,7 @@
|
||||
|
||||
$table->setPrimaryKey(['id']);
|
||||
$table->addIndex(['user_id'], 'mywiki_user_id_index');
|
||||
$table->addIndex(['file_id'], 'mywiki_file_id_index');
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -25,7 +25,7 @@ class WikiService {
|
||||
}
|
||||
|
||||
public function test() {
|
||||
$folderId = 381;
|
||||
$folderId = 880;
|
||||
return $this->wikiHelper->setFolderId($folderId)->reloadWikiTree();
|
||||
return $this->wikiHelper->setFolderId($folderId)->rename(707, 'UnoMasUno');
|
||||
return $this->wikiHelper->setFolderId($folderId)->rename(647, 'RenameTest3');
|
||||
@ -57,17 +57,20 @@ class WikiService {
|
||||
}
|
||||
}
|
||||
|
||||
public function create(string $title, int $fileId, string $userId) {
|
||||
$this->wikiHelper->setFolderId($fileId);
|
||||
if ( $this->wikiHelper->isWiki() ) {
|
||||
if ( !$this->wikiHelper->initWiki($title) ) {
|
||||
public function create(string $folderPath, string $title, string $userId) {
|
||||
$folderId = $this->wikiHelper->initWiki($folderPath, $title);
|
||||
if ( $folderId === null ) {
|
||||
throw new ReadOnlyException('Error creating wiki');
|
||||
}
|
||||
|
||||
$wikis = $this->mapper->findAll($userId, ['fileId'=>$folderId]);
|
||||
if ( count($wikis)>0 ) {
|
||||
return $wikis[0];
|
||||
}
|
||||
|
||||
$wiki = new Wiki();
|
||||
$wiki->setTitle($title);
|
||||
$wiki->setFileId($fileId);
|
||||
$wiki->setFileId($folderId);
|
||||
$wiki->setUserId($userId);
|
||||
return $this->mapper->insert($wiki);
|
||||
}
|
||||
|
@ -1,4 +1,6 @@
|
||||
<?php
|
||||
\OCP\Util::addScript('mywiki', 'WikiDropdownHelper');
|
||||
\OCP\Util::addScript('mywiki', 'WikiNavigation');
|
||||
\OCP\Util::addScript('mywiki', 'script');
|
||||
\OCP\Util::addStyle('mywiki', 'style');
|
||||
?>
|
||||
|
@ -1,10 +1,51 @@
|
||||
<ul>
|
||||
<li><a href="#">First level entry</a></li>
|
||||
<li>
|
||||
<a href="#">First level container</a>
|
||||
<li data-id="wikis">
|
||||
<select></select>
|
||||
<div class="app-navigation-entry-utils">
|
||||
<ul>
|
||||
<li><a href="#">Second level entry</a></li>
|
||||
<li><a href="#">Second level entry</a></li>
|
||||
<li class="app-navigation-entry-utils-menu-button">
|
||||
<button></button>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="app-navigation-entry-menu">
|
||||
<ul>
|
||||
<li>
|
||||
<a href="#" data-id="add">
|
||||
<span class="icon-add"></span>
|
||||
<span>Add</span>
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="#" data-id="rename">
|
||||
<span class="icon-rename"></span>
|
||||
<span>Edit</span>
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="#" data-id="delete">
|
||||
<span class="icon-delete"></span>
|
||||
<span>Remove</span>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</li>
|
||||
|
||||
|
||||
<li data-id="pages">
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<div id="myWikiTree">
|
||||
no data
|
||||
</div>
|
@ -6,5 +6,10 @@
|
||||
</div>
|
||||
<div id="app-settings-content">
|
||||
<!-- Your settings in here -->
|
||||
<ul class="with-icon">
|
||||
<li data-id="deleteWiki">
|
||||
<a href="#" class="icon-delete svg">Delete Current Wiki</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
4
vendor/composer/installed.php
vendored
4
vendor/composer/installed.php
vendored
@ -5,7 +5,7 @@
|
||||
'type' => 'project',
|
||||
'install_path' => __DIR__ . '/../../',
|
||||
'aliases' => array(),
|
||||
'reference' => 'a30a4f13ec699c6e80f32148dc3aa017511c5f5a',
|
||||
'reference' => '9c6114cf8643a84a9536074942d2e7f1a8451cd0',
|
||||
'name' => 'jdg/mywiki',
|
||||
'dev' => true,
|
||||
),
|
||||
@ -25,7 +25,7 @@
|
||||
'type' => 'project',
|
||||
'install_path' => __DIR__ . '/../../',
|
||||
'aliases' => array(),
|
||||
'reference' => 'a30a4f13ec699c6e80f32148dc3aa017511c5f5a',
|
||||
'reference' => '9c6114cf8643a84a9536074942d2e7f1a8451cd0',
|
||||
'dev_requirement' => false,
|
||||
),
|
||||
'myclabs/deep-copy' => array(
|
||||
|
Loading…
x
Reference in New Issue
Block a user