diff --git a/README.md b/README.md index 8a430d0..3eb4993 100644 --- a/README.md +++ b/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: diff --git a/css/style.css b/css/style.css index ce350c6..2eed7fb 100644 --- a/css/style.css +++ b/css/style.css @@ -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; +} diff --git a/js/script.js b/js/script.js index a3b437e..68392dd 100644 --- a/js/script.js +++ b/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('
'+response.responseText+'
');
});
}
+ // ---------------------------------------------------------------------------------
-/*
- // if this function or object should be global, attach it to the namespace
- exports.myGlobalFunction = function(params) {
- return params;
- };
-*/
})(window, jQuery, MyWiki);
diff --git a/lib/Controller/WikiController.php b/lib/Controller/WikiController.php
index 8876936..1a6ba5c 100644
--- a/lib/Controller/WikiController.php
+++ b/lib/Controller/WikiController.php
@@ -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);
});
}
diff --git a/lib/Db/Wiki.php b/lib/Db/Wiki.php
index 77dd7f1..517bff4 100644
--- a/lib/Db/Wiki.php
+++ b/lib/Db/Wiki.php
@@ -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
];
}
}
\ No newline at end of file
diff --git a/lib/Db/WikiMapper.php b/lib/Db/WikiMapper.php
index 644b2b2..55090c2 100644
--- a/lib/Db/WikiMapper.php
+++ b/lib/Db/WikiMapper.php
@@ -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) {
@@ -24,18 +24,17 @@ class WikiMapper extends QBMapper {
public function find(int $id, string $userId) {
$qb = $this->db->getQueryBuilder();
- $qb->select('*')
- ->from($this->getTableName())
- ->where(
- $qb->expr()->eq('id', $qb->createNamedParameter($id))
- )->andWhere(
- $qb->expr()->eq('user_id', $qb->createNamedParameter($userId))
- );
-
+ $qb->select('*')
+ ->from($this->getTableName())
+ ->where(
+ $qb->expr()->eq('id', $qb->createNamedParameter($id))
+ )->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);
}
diff --git a/lib/Helper/WikiHelper.php b/lib/Helper/WikiHelper.php
index 9097074..a77e721 100644
--- a/lib/Helper/WikiHelper.php
+++ b/lib/Helper/WikiHelper.php
@@ -96,16 +96,24 @@ class WikiHelper {
return true;
}
- public function initWiki(string $title) :bool {
- $wiki = [
- "title"=>$title,
- "folderId"=>$this->wikiFolder->getId(),
- "pages"=>$this->rebuildWikiTree()
- ];
- if ( $this->getWikiData() === null ) {
- return $this->setWikiData($wiki);
+ public function initWiki(string $folderPath, string $title) :?int {
+ $this->wikiFolder = $this->userFolder->get($folderPath);
+ if ( !$this->isWiki() ) {
+ return null;
}
- return true;
+
+ $folderId = $this->wikiFolder->getId();
+ if ( $this->getWikiData() === null ) {
+ $wiki = [
+ "title"=>$title,
+ "folderId"=>$folderId,
+ "pages"=>$this->rebuildWikiTree()
+ ];
+ if ( !$this->setWikiData($wiki) ) {
+ return null;
+ }
+ }
+ return $folderId;
}
public function add(int $parentId, string $title) {
diff --git a/lib/Migration/Version000000Date20220302210900.php b/lib/Migration/Version000000Date20220302210900.php
index 17b60a9..dc4250c 100644
--- a/lib/Migration/Version000000Date20220302210900.php
+++ b/lib/Migration/Version000000Date20220302210900.php
@@ -39,6 +39,7 @@
$table->setPrimaryKey(['id']);
$table->addIndex(['user_id'], 'mywiki_user_id_index');
+ $table->addIndex(['file_id'], 'mywiki_file_id_index');
}
/*
diff --git a/lib/Service/WikiService.php b/lib/Service/WikiService.php
index 887b4c5..6376bdf 100644
--- a/lib/Service/WikiService.php
+++ b/lib/Service/WikiService.php
@@ -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) ) {
- throw new ReadOnlyException('Error creating wiki');
- }
+ 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);
}
diff --git a/templates/index.php b/templates/index.php
index 12ac33e..c6f2d53 100644
--- a/templates/index.php
+++ b/templates/index.php
@@ -1,4 +1,6 @@
diff --git a/templates/navigation/index.php b/templates/navigation/index.php
index efa95c6..b14f4c5 100644
--- a/templates/navigation/index.php
+++ b/templates/navigation/index.php
@@ -1,10 +1,51 @@