mirror of https://github.com/sualko/cloud_bbb
refactor: use consistent indentation for ts
parent
4b901f205a
commit
938e8ee68c
|
@ -28,5 +28,6 @@ module.exports = {
|
|||
'comma-dangle': ['error', 'always-multiline'],
|
||||
'array-bracket-newline': ['error', 'consistent'],
|
||||
'quote-props': ['error', 'as-needed'],
|
||||
'indent': ['warn', 'tab'],
|
||||
},
|
||||
}
|
|
@ -12,20 +12,20 @@ enum SortOrder { DESC = -1, ASC = 1 };
|
|||
function sortRooms(key: SortKey, orderBy: SortOrder) {
|
||||
return (a: Room, b: Room) => {
|
||||
switch (key) {
|
||||
case 'name':
|
||||
case 'welcome':
|
||||
return a[key].localeCompare(b[key]) * orderBy;
|
||||
case 'maxParticipants':
|
||||
return (a.maxParticipants - b.maxParticipants) * orderBy;
|
||||
case 'record':
|
||||
if (a.record && !b.record) {
|
||||
return 1 * orderBy;
|
||||
}
|
||||
if (!a.record && b.record) {
|
||||
return -1 * orderBy;
|
||||
}
|
||||
case 'name':
|
||||
case 'welcome':
|
||||
return a[key].localeCompare(b[key]) * orderBy;
|
||||
case 'maxParticipants':
|
||||
return (a.maxParticipants - b.maxParticipants) * orderBy;
|
||||
case 'record':
|
||||
if (a.record && !b.record) {
|
||||
return 1 * orderBy;
|
||||
}
|
||||
if (!a.record && b.record) {
|
||||
return -1 * orderBy;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,27 +5,27 @@ type Props = {
|
|||
}
|
||||
|
||||
const NewRoomForm: React.FC<Props> = (props) => {
|
||||
const [name, setName] = useState('');
|
||||
const [name, setName] = useState('');
|
||||
|
||||
function addRoom(ev: React.FormEvent) {
|
||||
ev.preventDefault();
|
||||
function addRoom(ev: React.FormEvent) {
|
||||
ev.preventDefault();
|
||||
|
||||
props.addRoom(name);
|
||||
props.addRoom(name);
|
||||
|
||||
setName('');
|
||||
setName('');
|
||||
}
|
||||
|
||||
return (
|
||||
<form action="#" onSubmit={addRoom}>
|
||||
<input
|
||||
className="newgroup-name"
|
||||
value={name}
|
||||
placeholder="Room name"
|
||||
onChange={(event) => {setName(event.target.value)}} />
|
||||
return (
|
||||
<form action="#" onSubmit={addRoom}>
|
||||
<input
|
||||
className="newgroup-name"
|
||||
value={name}
|
||||
placeholder="Room name"
|
||||
onChange={(event) => {setName(event.target.value)}} />
|
||||
|
||||
<input type="submit" value="Create" />
|
||||
</form>
|
||||
)
|
||||
<input type="submit" value="Create" />
|
||||
</form>
|
||||
)
|
||||
}
|
||||
|
||||
export default NewRoomForm;
|
|
@ -19,87 +19,87 @@ type EditableValueProps = {
|
|||
}
|
||||
|
||||
const EditableValue: React.FC<EditableValueProps> = ({ setValue, setActive, active, field, value, type }) => {
|
||||
if (active === field) {
|
||||
return <SubmitInput
|
||||
autoFocus={true}
|
||||
onSubmitValue={(value) => setValue(field, type === 'number' ? parseInt(value):value)}
|
||||
onClick={event => event.stopPropagation()}
|
||||
initialValue={value}
|
||||
type={type}
|
||||
/>
|
||||
}
|
||||
if (active === field) {
|
||||
return <SubmitInput
|
||||
autoFocus={true}
|
||||
onSubmitValue={(value) => setValue(field, type === 'number' ? parseInt(value):value)}
|
||||
onClick={event => event.stopPropagation()}
|
||||
initialValue={value}
|
||||
type={type}
|
||||
/>
|
||||
}
|
||||
|
||||
function onClick(ev) {
|
||||
ev.stopPropagation();
|
||||
function onClick(ev) {
|
||||
ev.stopPropagation();
|
||||
|
||||
setActive(field);
|
||||
}
|
||||
setActive(field);
|
||||
}
|
||||
|
||||
return <a className="action-rename" onClick={onClick}>{value}</a>;
|
||||
return <a className="action-rename" onClick={onClick}>{value}</a>;
|
||||
}
|
||||
|
||||
const RoomRow: React.FC<Props> = (props) => {
|
||||
const [activeEdit, setActiveEdit] = useState('');
|
||||
const room = props.room;
|
||||
const [activeEdit, setActiveEdit] = useState('');
|
||||
const room = props.room;
|
||||
|
||||
function updateRoom(key: string, value: string|boolean|number) {
|
||||
props.updateRoom({
|
||||
...props.room,
|
||||
[key]: value,
|
||||
});
|
||||
function updateRoom(key: string, value: string|boolean|number) {
|
||||
props.updateRoom({
|
||||
...props.room,
|
||||
[key]: value,
|
||||
});
|
||||
|
||||
setActiveEdit('');
|
||||
}
|
||||
setActiveEdit('');
|
||||
}
|
||||
|
||||
function deleteRow(ev: MouseEvent) {
|
||||
ev.preventDefault();
|
||||
function deleteRow(ev: MouseEvent) {
|
||||
ev.preventDefault();
|
||||
|
||||
OC.dialogs.confirm(
|
||||
t('bbb', 'Are you sure you want to delete "{name}"? This operation can not be undone', { name: room.name }),
|
||||
t('bbb', 'Delete "{name}"?', { name: room.name }),
|
||||
confirmed => {
|
||||
if (confirmed) {
|
||||
props.deleteRoom(room.id);
|
||||
}
|
||||
},
|
||||
true
|
||||
);
|
||||
}
|
||||
OC.dialogs.confirm(
|
||||
t('bbb', 'Are you sure you want to delete "{name}"? This operation can not be undone', { name: room.name }),
|
||||
t('bbb', 'Delete "{name}"?', { name: room.name }),
|
||||
confirmed => {
|
||||
if (confirmed) {
|
||||
props.deleteRoom(room.id);
|
||||
}
|
||||
},
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
function edit(field: string, type: 'text' | 'number' = 'text'){
|
||||
return <EditableValue field={field} value={room[field]} active={activeEdit} setActive={setActiveEdit} setValue={updateRoom} type={type} />
|
||||
}
|
||||
function edit(field: string, type: 'text' | 'number' = 'text'){
|
||||
return <EditableValue field={field} value={room[field]} active={activeEdit} setActive={setActiveEdit} setValue={updateRoom} type={type} />
|
||||
}
|
||||
|
||||
return (
|
||||
<tr key={room.id}>
|
||||
<td className="share icon-col">
|
||||
<CopyToClipboard text={window.location.origin + api.getUrl(`b/${room.uid}`)}>
|
||||
<span className="icon icon-clippy icon-visible copy-to-clipboard" ></span>
|
||||
</CopyToClipboard>
|
||||
</td>
|
||||
<td className="start icon-col">
|
||||
<a href={api.getUrl(`b/${room.uid}`)} className="icon icon-play icon-visible" target="_blank" rel="noopener noreferrer"></a>
|
||||
</td>
|
||||
<td className="name">
|
||||
{edit('name')}
|
||||
</td>
|
||||
<td className="welcome">
|
||||
{edit('welcome')}
|
||||
</td>
|
||||
<td className="max-participants">
|
||||
{edit('maxParticipants', 'number')}
|
||||
</td>
|
||||
<td className="record">
|
||||
<input id={`bbb-record-${room.id}`} type="checkbox" className="checkbox" checked={room.record} onChange={(event) => updateRoom('record', event.target.checked)} />
|
||||
<label htmlFor={`bbb-record-${room.id}`}></label>
|
||||
</td>
|
||||
<td className="remove icon-col">
|
||||
<a className="icon icon-delete icon-visible"
|
||||
onClick={deleteRow as any}
|
||||
title="Delete" />
|
||||
</td>
|
||||
</tr>
|
||||
)
|
||||
return (
|
||||
<tr key={room.id}>
|
||||
<td className="share icon-col">
|
||||
<CopyToClipboard text={window.location.origin + api.getUrl(`b/${room.uid}`)}>
|
||||
<span className="icon icon-clippy icon-visible copy-to-clipboard" ></span>
|
||||
</CopyToClipboard>
|
||||
</td>
|
||||
<td className="start icon-col">
|
||||
<a href={api.getUrl(`b/${room.uid}`)} className="icon icon-play icon-visible" target="_blank" rel="noopener noreferrer"></a>
|
||||
</td>
|
||||
<td className="name">
|
||||
{edit('name')}
|
||||
</td>
|
||||
<td className="welcome">
|
||||
{edit('welcome')}
|
||||
</td>
|
||||
<td className="max-participants">
|
||||
{edit('maxParticipants', 'number')}
|
||||
</td>
|
||||
<td className="record">
|
||||
<input id={`bbb-record-${room.id}`} type="checkbox" className="checkbox" checked={room.record} onChange={(event) => updateRoom('record', event.target.checked)} />
|
||||
<label htmlFor={`bbb-record-${room.id}`}></label>
|
||||
</td>
|
||||
<td className="remove icon-col">
|
||||
<a className="icon icon-delete icon-visible"
|
||||
onClick={deleteRow as any}
|
||||
title="Delete" />
|
||||
</td>
|
||||
</tr>
|
||||
)
|
||||
}
|
||||
|
||||
export default RoomRow;
|
|
@ -7,11 +7,11 @@ export interface SortArrowProps {
|
|||
}
|
||||
|
||||
export function SortArrow({name, value, direction}: SortArrowProps) {
|
||||
if (name === value) {
|
||||
return (<span className='sort_arrow'>
|
||||
{direction < 0 ? '▼' : '▲'}
|
||||
</span>);
|
||||
} else {
|
||||
return <span/>;
|
||||
}
|
||||
if (name === value) {
|
||||
return (<span className='sort_arrow'>
|
||||
{direction < 0 ? '▼' : '▲'}
|
||||
</span>);
|
||||
} else {
|
||||
return <span/>;
|
||||
}
|
||||
}
|
10
ts/admin.ts
10
ts/admin.ts
|
@ -1,10 +1,10 @@
|
|||
declare const OCP: any;
|
||||
|
||||
$(() => {
|
||||
$('#bbb-settings form').submit(function (ev) {
|
||||
ev.preventDefault();
|
||||
$('#bbb-settings form').submit(function (ev) {
|
||||
ev.preventDefault();
|
||||
|
||||
OCP.AppConfig.setValue('bbb', 'api.url', this['api.url'].value);
|
||||
OCP.AppConfig.setValue('bbb', 'api.secret', this['api.secret'].value);
|
||||
})
|
||||
OCP.AppConfig.setValue('bbb', 'api.url', this['api.url'].value);
|
||||
OCP.AppConfig.setValue('bbb', 'api.secret', this['api.secret'].value);
|
||||
})
|
||||
});
|
144
ts/filelist.ts
144
ts/filelist.ts
|
@ -5,97 +5,97 @@ import { Room } from './Manager/Api';
|
|||
declare const OCA: any;
|
||||
|
||||
class BigBlueButton {
|
||||
public async getRooms(): Promise<Room[]> {
|
||||
const response = await axios.get(OC.generateUrl('/apps/bbb/rooms'))
|
||||
public async getRooms(): Promise<Room[]> {
|
||||
const response = await axios.get(OC.generateUrl('/apps/bbb/rooms'))
|
||||
|
||||
return response.data
|
||||
}
|
||||
return response.data
|
||||
}
|
||||
}
|
||||
|
||||
$(() => {
|
||||
|
||||
if (!OCA?.Files?.fileActions) {
|
||||
return;
|
||||
}
|
||||
if (!OCA?.Files?.fileActions) {
|
||||
return;
|
||||
}
|
||||
|
||||
const mimeTypes = [
|
||||
'application/pdf',
|
||||
'application/vnd.oasis.opendocument.presentation',
|
||||
'application/vnd.oasis.opendocument.text',
|
||||
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
||||
'application/vnd.openxmlformats-officedocument.presentationml.presentation',
|
||||
'application/msword',
|
||||
'application/vnd.ms-powerpoint',
|
||||
];
|
||||
const bbb = new BigBlueButton();
|
||||
const mimeTypes = [
|
||||
'application/pdf',
|
||||
'application/vnd.oasis.opendocument.presentation',
|
||||
'application/vnd.oasis.opendocument.text',
|
||||
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
||||
'application/vnd.openxmlformats-officedocument.presentationml.presentation',
|
||||
'application/msword',
|
||||
'application/vnd.ms-powerpoint',
|
||||
];
|
||||
const bbb = new BigBlueButton()
|
||||
|
||||
bbb.getRooms().then(rooms => {
|
||||
rooms.forEach(room => {
|
||||
mimeTypes.forEach(mime => registerFileAction(mime, room.id, room.uid, room.name));
|
||||
})
|
||||
});
|
||||
bbb.getRooms().then(rooms => {
|
||||
rooms.forEach(room => {
|
||||
mimeTypes.forEach(mime => registerFileAction(mime, room.id, room.uid, room.name));
|
||||
})
|
||||
});
|
||||
|
||||
function registerFileAction(mime, id, uid, name) {
|
||||
OCA.Files.fileActions.registerAction({
|
||||
name: 'bbb-' + id,
|
||||
displayName: name,
|
||||
mime,
|
||||
permissions: OC.PERMISSION_SHARE,
|
||||
icon: OC.imagePath('bbb', 'app-dark.svg'),
|
||||
actionHandler: (fileName, context) => {
|
||||
share(context.fileInfoModel.getFullPath(), fileName, uid);
|
||||
},
|
||||
});
|
||||
}
|
||||
function registerFileAction(mime, id, uid, name) {
|
||||
OCA.Files.fileActions.registerAction({
|
||||
name: 'bbb-' + id,
|
||||
displayName: name,
|
||||
mime,
|
||||
permissions: OC.PERMISSION_SHARE,
|
||||
icon: OC.imagePath('bbb', 'app-dark.svg'),
|
||||
actionHandler: (fileName, context) => {
|
||||
share(context.fileInfoModel.getFullPath(), fileName, uid);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async function share(path: string, filename: string, roomUid) {
|
||||
const id = await createShare(path);
|
||||
const shareUrl = await configureShare(id);
|
||||
const joinUrl = generateUrl('/apps/bbb/b/{uid}?u={url}&filename={filename}', {
|
||||
uid: roomUid,
|
||||
url: shareUrl + '/download',
|
||||
filename,
|
||||
});
|
||||
async function share(path: string, filename: string, roomUid) {
|
||||
const id = await createShare(path);
|
||||
const shareUrl = await configureShare(id);
|
||||
const joinUrl = generateUrl('/apps/bbb/b/{uid}?u={url}&filename={filename}', {
|
||||
uid: roomUid,
|
||||
url: shareUrl + '/download',
|
||||
filename,
|
||||
});
|
||||
|
||||
window.open(joinUrl, '_blank', 'noopener,noreferrer');
|
||||
}
|
||||
window.open(joinUrl, '_blank', 'noopener,noreferrer');
|
||||
}
|
||||
|
||||
async function createShare(path: string): Promise<number> {
|
||||
const url = generateOcsUrl('apps/files_sharing/api/v1', 2) + 'shares';
|
||||
async function createShare(path: string): Promise<number> {
|
||||
const url = generateOcsUrl('apps/files_sharing/api/v1', 2) + 'shares';
|
||||
|
||||
const createResponse = await axios.post(url, {
|
||||
path,
|
||||
shareType: OC.Share.SHARE_TYPE_LINK,
|
||||
note: 'foobar foobar foobar',
|
||||
expireDate: '2020-07-01',
|
||||
});
|
||||
const createResponse = await axios.post(url, {
|
||||
path,
|
||||
shareType: OC.Share.SHARE_TYPE_LINK,
|
||||
note: 'foobar foobar foobar',
|
||||
expireDate: '2020-07-01',
|
||||
});
|
||||
|
||||
const { meta, data } = createResponse.data.ocs;
|
||||
const { meta, data } = createResponse.data.ocs;
|
||||
|
||||
if (meta.statuscode !== 200) {
|
||||
throw new Error('Failed to create share');
|
||||
}
|
||||
if (meta.statuscode !== 200) {
|
||||
throw new Error('Failed to create share');
|
||||
}
|
||||
|
||||
return data.id;
|
||||
}
|
||||
return data.id;
|
||||
}
|
||||
|
||||
async function configureShare(id: number): Promise<string> {
|
||||
const url = generateOcsUrl('apps/files_sharing/api/v1', 2) + 'shares/' + id;
|
||||
async function configureShare(id: number): Promise<string> {
|
||||
const url = generateOcsUrl('apps/files_sharing/api/v1', 2) + 'shares/' + id;
|
||||
|
||||
const tomorrow = new Date();
|
||||
tomorrow.setDate(new Date().getDate() + 1);
|
||||
const tomorrow = new Date();
|
||||
tomorrow.setDate(new Date().getDate() + 1);
|
||||
|
||||
const updateResponse = await axios.put(url, {
|
||||
expireDate: tomorrow.toISOString().split('T')[0],
|
||||
note: 'BigBlueButton',
|
||||
});
|
||||
const updateResponse = await axios.put(url, {
|
||||
expireDate: tomorrow.toISOString().split('T')[0],
|
||||
note: 'BigBlueButton',
|
||||
});
|
||||
|
||||
const { meta, data } = updateResponse.data.ocs;
|
||||
const { meta, data } = updateResponse.data.ocs;
|
||||
|
||||
if (meta.statuscode !== 200) {
|
||||
throw new Error('Failed to configure share');
|
||||
}
|
||||
if (meta.statuscode !== 200) {
|
||||
throw new Error('Failed to configure share');
|
||||
}
|
||||
|
||||
return data.url;
|
||||
}
|
||||
return data.url;
|
||||
}
|
||||
});
|
Loading…
Reference in New Issue