mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
The web app manifest declares a share_target, so on a phone where WeKan is installed as an app it appears in Android's Share menu. Sharing a web page, a note or a message opens /share-target, "Add to WeKan": pick a board and a list, and what was shared becomes a card there - the page's title or the text's first line as the title, the text and the address in its description, the address once - and the card opens. Only boards the member may add cards to are offered, and the server checks the right to write in that list, on that board, as for any card added. models/lib/shareTarget.js turns a share into a card and holds the manifest's declaration; tests/shareTarget.test.cjs covers what browsers, notes and chat apps share, an empty share, javascript: addresses, the manifest, the route and the server's checks. Documented in docs/Platforms/FOSS/OS/Android.md. The four new strings are English placeholders until the next translation pass. Thanks to memeplex and xet7 ! Fixes #1293.
63 lines
2.4 KiB
JavaScript
63 lines
2.4 KiB
JavaScript
import { ReactiveVar } from 'meteor/reactive-var';
|
|
import { FlowRouter } from 'meteor/ostrio:flow-router-extra';
|
|
import { ReactiveCache } from '/imports/reactiveCache';
|
|
import { TAPi18n } from '/imports/i18n';
|
|
|
|
const { sharedCard } = require('/models/lib/shareTarget');
|
|
|
|
// #1293: the page Share → WeKan opens on a phone.
|
|
function shared() {
|
|
return {
|
|
title: FlowRouter.getQueryParam('title') || '',
|
|
text: FlowRouter.getQueryParam('text') || '',
|
|
url: FlowRouter.getQueryParam('url') || '',
|
|
};
|
|
}
|
|
|
|
Template.shareTarget.onCreated(function () {
|
|
this.boardId = new ReactiveVar('');
|
|
this.message = new ReactiveVar('');
|
|
this.subscribe('boards');
|
|
this.autorun(() => {
|
|
const boardId = this.boardId.get();
|
|
if (boardId) this.subscribe('board', boardId, false);
|
|
});
|
|
});
|
|
|
|
Template.shareTarget.helpers({
|
|
preview() { return sharedCard(shared()); },
|
|
// Boards the member may add cards to; the server checks the list too.
|
|
writableBoards() {
|
|
const user = ReactiveCache.getCurrentUser();
|
|
if (!user) return [];
|
|
return ReactiveCache.getBoards({ archived: false, type: { $ne: 'template-container' }, members: { $elemMatch: {
|
|
userId: user._id, isActive: true, isReadOnly: { $ne: true }, isCommentOnly: { $ne: true },
|
|
isNoComments: { $ne: true }, isReadAssignedOnly: { $ne: true } } } }, { sort: { title: 1 } });
|
|
},
|
|
isSelectedBoard() { return this._id === Template.instance().boardId.get(); },
|
|
noBoard() { return !Template.instance().boardId.get(); },
|
|
boardLists() {
|
|
const boardId = Template.instance().boardId.get();
|
|
return boardId ? ReactiveCache.getLists({ boardId, archived: false }, { sort: { sort: 1 } }) : [];
|
|
},
|
|
message() { return Template.instance().message.get(); },
|
|
});
|
|
|
|
Template.shareTarget.events({
|
|
'change .js-share-target-board'(event, tpl) {
|
|
tpl.boardId.set(event.currentTarget.value);
|
|
},
|
|
async 'submit .js-share-target-form, click .js-share-target-create'(event, tpl) {
|
|
event.preventDefault();
|
|
const boardId = tpl.boardId.get();
|
|
const listId = tpl.$('.js-share-target-list').val();
|
|
if (!boardId || !listId) return;
|
|
try {
|
|
const result = await Meteor.callAsync('shareTargetCreateCard', { boardId, listId, ...shared() });
|
|
FlowRouter.go('card', { boardId: result.boardId, slug: result.slug, cardId: result.cardId });
|
|
} catch (error) {
|
|
tpl.message.set(TAPi18n.__(error.error) || error.reason || error.message);
|
|
}
|
|
},
|
|
});
|