@@ -187,6 +187,7 @@ class Application extends App {
|
||||
/** @var IManager $resourceManager */
|
||||
$resourceManager = $this->getContainer()->query(IManager::class);
|
||||
$resourceManager->registerResourceProvider(\OCA\Deck\Collaboration\Resources\ResourceProvider::class);
|
||||
$resourceManager->registerResourceProvider(\OCA\Deck\Collaboration\Resources\ResourceProviderCard::class);
|
||||
\OC::$server->getEventDispatcher()->addListener('\OCP\Collaboration\Resources::loadAdditionalScripts', function () {
|
||||
\OCP\Util::addScript('deck', 'collections');
|
||||
});
|
||||
|
||||
133
lib/Collaboration/Resources/ResourceProviderCard.php
Normal file
133
lib/Collaboration/Resources/ResourceProviderCard.php
Normal file
@@ -0,0 +1,133 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2019 Julius Härtl <jus@bitgrid.net>
|
||||
*
|
||||
* @author Julius Härtl <jus@bitgrid.net>
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\Deck\Collaboration\Resources;
|
||||
|
||||
|
||||
use OCA\Deck\Db\Acl;
|
||||
use OCA\Deck\Db\Board;
|
||||
use OCA\Deck\Db\BoardMapper;
|
||||
use OCA\Deck\Service\PermissionService;
|
||||
use OCP\AppFramework\Db\DoesNotExistException;
|
||||
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
|
||||
use OCP\AppFramework\QueryException;
|
||||
use OCP\Collaboration\Resources\IManager;
|
||||
use OCP\Collaboration\Resources\IProvider;
|
||||
use OCP\Collaboration\Resources\IResource;
|
||||
use OCP\Collaboration\Resources\ResourceException;
|
||||
use OCP\IUser;
|
||||
|
||||
class ResourceProviderCard implements IProvider {
|
||||
|
||||
const RESOURCE_TYPE = 'deck-card';
|
||||
|
||||
private $boardMapper;
|
||||
private $permissionService;
|
||||
|
||||
/** @var array */
|
||||
protected $nodes = [];
|
||||
|
||||
public function __construct(BoardMapper $boardMapper, PermissionService $permissionService) {
|
||||
$this->boardMapper = $boardMapper;
|
||||
$this->permissionService = $permissionService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the type of a resource
|
||||
*
|
||||
* @param IResource $resource
|
||||
* @return string
|
||||
* @since 15.0.0
|
||||
*/
|
||||
public function getType(): string {
|
||||
return self::RESOURCE_TYPE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the rich object data of a resource
|
||||
*
|
||||
* @param IResource $resource
|
||||
* @return array
|
||||
* @throws \OCP\AppFramework\Db\DoesNotExistException
|
||||
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
|
||||
* @since 16.0.0
|
||||
*/
|
||||
public function getResourceRichObject(IResource $resource): array {
|
||||
$board = $this->getBoard($resource);
|
||||
$link = \OC::$server->getURLGenerator()->linkToRoute('deck.page.index') . '#!/board/' . $resource->getId();
|
||||
|
||||
return [
|
||||
'type' => self::RESOURCE_TYPE,
|
||||
'id' => $resource->getId(),
|
||||
'name' => $board->getTitle(),
|
||||
'link' => $link,
|
||||
'iconUrl' => \OC::$server->getURLGenerator()->imagePath('deck', 'deck-dark.svg')
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Can a user/guest access the collection
|
||||
*
|
||||
* @param IResource $resource
|
||||
* @param IUser|null $user
|
||||
* @return bool
|
||||
* @since 16.0.0
|
||||
*/
|
||||
public function canAccessResource(IResource $resource, ?IUser $user): bool {
|
||||
if ($resource->getType() !== self::RESOURCE_TYPE || !$user instanceof IUser) {
|
||||
return false;
|
||||
}
|
||||
$board = $this->getBoard($resource);
|
||||
if ($board === null) {
|
||||
return false;
|
||||
}
|
||||
if ($board->getOwner() === $user->getUID()) {
|
||||
return true;
|
||||
}
|
||||
return $this->permissionService->userCan($board->getAcl(), Acl::PERMISSION_READ, $user->getUID());
|
||||
}
|
||||
|
||||
private function getBoard(IResource $resource) {
|
||||
try {
|
||||
return $this->boardMapper->find($resource->getId(), false, true);
|
||||
} catch (DoesNotExistException $e) {
|
||||
} catch (MultipleObjectsReturnedException $e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function invalidateAccessCache($boardId = null) {
|
||||
try {
|
||||
/** @var IManager $resourceManager */
|
||||
$resourceManager = \OC::$server->query(IManager::class);
|
||||
} catch (QueryException $e) {
|
||||
}
|
||||
if ($boardId !== null) {
|
||||
$resource = $resourceManager->getResourceForUser(self::RESOURCE_TYPE, (string)$boardId, null);
|
||||
$resourceManager->invalidateAccessCacheForResource($resource);
|
||||
} else {
|
||||
$resourceManager->invalidateAccessCacheForProvider($this);
|
||||
}
|
||||
}
|
||||
}
|
||||
119
src/CardSelector.vue
Normal file
119
src/CardSelector.vue
Normal file
@@ -0,0 +1,119 @@
|
||||
<!--
|
||||
- @copyright Copyright (c) 2019 Julius Härtl <jus@bitgrid.net>
|
||||
-
|
||||
- @author Julius Härtl <jus@bitgrid.net>
|
||||
-
|
||||
- @license GNU AGPL version 3 or any later version
|
||||
-
|
||||
- This program is free software: you can redistribute it and/or modify
|
||||
- it under the terms of the GNU Affero General Public License as
|
||||
- published by the Free Software Foundation, either version 3 of the
|
||||
- License, or (at your option) any later version.
|
||||
-
|
||||
- This program is distributed in the hope that it will be useful,
|
||||
- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
- GNU Affero General Public License for more details.
|
||||
-
|
||||
- You should have received a copy of the GNU Affero General Public License
|
||||
- along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
-
|
||||
-->
|
||||
|
||||
<template>
|
||||
<Modal @close="close">
|
||||
<div id="modal-inner" :class="{ 'icon-loading': loading }">
|
||||
<h1>{{ t('deck', 'Select the card to link to a project') }}</h1>
|
||||
<ul v-if="!loading">
|
||||
<li v-for="board in boards" v-if="!currentBoard || ''+board.id !== ''+currentBoard" :class="{'selected': (selectedBoard === board.id) }"
|
||||
@click="selectedBoard=board.id">
|
||||
<span :style="{ 'backgroundColor': '#' + board.color }" class="board-bullet" />
|
||||
<span>{{ board.title }}</span>
|
||||
</li>
|
||||
</ul>
|
||||
<button v-if="!loading" class="primary" @click="select">{{ t('deck', 'Select board') }}</button>
|
||||
</div>
|
||||
</Modal>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
/* global OC */
|
||||
import { Modal } from 'nextcloud-vue/dist/Components/Modal'
|
||||
import { Avatar } from 'nextcloud-vue/dist/Components/Avatar'
|
||||
import axios from 'nextcloud-axios'
|
||||
|
||||
export default {
|
||||
name: 'CollaborationView',
|
||||
components: {
|
||||
Modal, Avatar
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
boards: [],
|
||||
selectedBoard: null,
|
||||
loading: true,
|
||||
currentBoard: null
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
|
||||
},
|
||||
beforeMount() {
|
||||
this.fetchBoards()
|
||||
if (typeof angular !== 'undefined' && angular.element('#board')) {
|
||||
try {
|
||||
this.currentBoard = angular.element('#board').scope().boardservice.id || null
|
||||
} catch (e) {}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
fetchBoards() {
|
||||
axios.get(OC.generateUrl('/apps/deck/boards')).then((response) => {
|
||||
this.boards = response.data
|
||||
this.loading = false
|
||||
})
|
||||
},
|
||||
close() {
|
||||
this.$root.$emit('close')
|
||||
},
|
||||
select() {
|
||||
this.$root.$emit('select', this.selectedBoard)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
#modal-inner {
|
||||
width: 90vw;
|
||||
max-width: 400px;
|
||||
padding: 20px;
|
||||
}
|
||||
ul {
|
||||
min-height: 100px;
|
||||
}
|
||||
li {
|
||||
padding: 6px;
|
||||
border: 1px solid transparent;
|
||||
}
|
||||
li:hover, li:focus {
|
||||
background-color: var(--color-background-dark);
|
||||
}
|
||||
li.selected {
|
||||
border: 1px solid var(--color-primary);
|
||||
}
|
||||
.board-bullet {
|
||||
display: inline-block;
|
||||
width: 12px;
|
||||
height: 12px;
|
||||
border: none;
|
||||
border-radius: 50%;
|
||||
cursor: pointer;
|
||||
}
|
||||
li > span,
|
||||
.avatar {
|
||||
vertical-align: middle;
|
||||
}
|
||||
</style>
|
||||
67
src/init-collections-card.js
Normal file
67
src/init-collections-card.js
Normal file
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* @copyright Copyright (c) 2019 Julius Härtl <jus@bitgrid.net>
|
||||
*
|
||||
* @author Julius Härtl <jus@bitgrid.net>
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
import Vue from 'vue'
|
||||
import CardSelector from './CardSelector'
|
||||
import './../css/collections.css'
|
||||
|
||||
'use strict'
|
||||
|
||||
/* global __webpack_nonce__ __webpack_public_path__ OC t n */
|
||||
// eslint-disable-next-line
|
||||
__webpack_nonce__ = btoa(OC.requestToken);
|
||||
// eslint-disable-next-line
|
||||
__webpack_public_path__ = OC.linkTo('deck', 'js/');
|
||||
|
||||
Vue.prototype.t = t
|
||||
Vue.prototype.n = n
|
||||
Vue.prototype.OC = OC;
|
||||
|
||||
((function(OCP) {
|
||||
|
||||
OCP.Collaboration.registerType('deck-card', {
|
||||
action: () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const container = document.createElement('div')
|
||||
container.id = 'deck-board-select'
|
||||
const body = document.getElementById('body-user')
|
||||
body.append(container)
|
||||
const ComponentVM = new Vue({
|
||||
render: h => h(CardSelector)
|
||||
})
|
||||
ComponentVM.$mount(container)
|
||||
ComponentVM.$root.$on('close', () => {
|
||||
ComponentVM.$el.remove()
|
||||
ComponentVM.$destroy()
|
||||
reject()
|
||||
})
|
||||
ComponentVM.$root.$on('select', (id) => {
|
||||
resolve(id)
|
||||
ComponentVM.$el.remove()
|
||||
ComponentVM.$destroy()
|
||||
})
|
||||
})
|
||||
},
|
||||
typeString: t('deck', 'Link to a card'),
|
||||
typeIconClass: 'icon-deck'
|
||||
})
|
||||
})(window.OCP))
|
||||
@@ -5,6 +5,7 @@ module.exports = {
|
||||
entry: {
|
||||
deck: path.join(__dirname, 'src', 'main.js'),
|
||||
collections: path.join(__dirname, 'src', 'init-collections.js'),
|
||||
collectionscard: path.join(__dirname, 'src', 'init-collections-card.js'),
|
||||
},
|
||||
output: {
|
||||
filename: '[name].js',
|
||||
|
||||
Reference in New Issue
Block a user