Skip to content

Commit

Permalink
Format js
Browse files Browse the repository at this point in the history
  • Loading branch information
imorland committed Jan 25, 2022
1 parent 07ae0bc commit b7a34a8
Show file tree
Hide file tree
Showing 18 changed files with 1,442 additions and 1,449 deletions.
1,009 changes: 505 additions & 504 deletions js/src/admin/components/UploadPage.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/src/admin/components/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import UploadPage from './UploadPage';

export const components = {
UploadPage,
UploadPage,
};
80 changes: 40 additions & 40 deletions js/src/admin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,44 @@ import UploadPage from './components/UploadPage';
export * from './components';

app.initializers.add('fof-upload', (app) => {
app.extensionData
.for('fof-upload')
.registerPage(UploadPage)
.registerPermission(
{
icon: 'far fa-file',
label: app.translator.trans('fof-upload.admin.permissions.upload_label'),
permission: 'fof-upload.upload',
},
'start',
50
)
.registerPermission(
{
icon: 'fas fa-download',
label: app.translator.trans('fof-upload.admin.permissions.download_label'),
permission: 'fof-upload.download',
allowGuest: true,
},
'view',
50
)
.registerPermission(
{
icon: 'fas fa-eye',
label: app.translator.trans('fof-upload.admin.permissions.view_user_uploads_label'),
permission: 'fof-upload.viewUserUploads',
},
'moderate',
50
)
.registerPermission(
{
icon: 'fas fa-trash',
label: app.translator.trans('fof-upload.admin.permissions.delete_uploads_of_others_label'),
permission: 'fof-upload.deleteUserUploads',
},
'moderate',
50
);
app.extensionData
.for('fof-upload')
.registerPage(UploadPage)
.registerPermission(
{
icon: 'far fa-file',
label: app.translator.trans('fof-upload.admin.permissions.upload_label'),
permission: 'fof-upload.upload',
},
'start',
50
)
.registerPermission(
{
icon: 'fas fa-download',
label: app.translator.trans('fof-upload.admin.permissions.download_label'),
permission: 'fof-upload.download',
allowGuest: true,
},
'view',
50
)
.registerPermission(
{
icon: 'fas fa-eye',
label: app.translator.trans('fof-upload.admin.permissions.view_user_uploads_label'),
permission: 'fof-upload.viewUserUploads',
},
'moderate',
50
)
.registerPermission(
{
icon: 'fas fa-trash',
label: app.translator.trans('fof-upload.admin.permissions.delete_uploads_of_others_label'),
permission: 'fof-upload.deleteUserUploads',
},
'moderate',
50
);
});
74 changes: 37 additions & 37 deletions js/src/common/mimeToIcon.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ const image = ['image/png', 'image/jpg', 'image/jpeg', 'image/svg+xml', 'image/g
const archive = ['application/zip', 'application/x-7z-compressed', 'application/gzip', 'application/vnd.rar', 'application/x-rar-compressed'];
const code = ['text/html', 'text/css', 'text/javascript', 'application/json', 'application/ld+json', 'text/javascript', 'application/x-httpd-php'];
const word = [
'application/x-abiword',
'application/msword',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'application/pdf',
'application/x-abiword',
'application/msword',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'application/pdf',
];

/**
Expand All @@ -17,38 +17,38 @@ const word = [
* @returns {string} Icon for MIME type
*/
export default function mimeToIcon(fileType) {
// Display image (do not display for)
if (image.includes(fileType)) {
return 'image';
}
// Display image icon for other types
else if (fileType.includes('image/')) {
return 'far fa-file-image';
}
// Video icon
else if (fileType.includes('video/')) {
return 'far fa-file-video';
}
// Archive icon
else if (archive.indexOf(fileType) >= 0) {
return 'far fa-file-archive';
}
// PDF icon
else if (fileType === 'application/pdf') {
return 'far fa-file-pdf';
}
// Word
else if (word.indexOf(fileType) >= 0) {
return 'far fa-file-word';
}
// Audio icon
else if (fileType.includes('audio/')) {
return 'far fa-file-audio';
}
// Code files
else if (code.indexOf(fileType) >= 0) {
return 'far fa-file-code';
}
// Display image (do not display for)
if (image.includes(fileType)) {
return 'image';
}
// Display image icon for other types
else if (fileType.includes('image/')) {
return 'far fa-file-image';
}
// Video icon
else if (fileType.includes('video/')) {
return 'far fa-file-video';
}
// Archive icon
else if (archive.indexOf(fileType) >= 0) {
return 'far fa-file-archive';
}
// PDF icon
else if (fileType === 'application/pdf') {
return 'far fa-file-pdf';
}
// Word
else if (word.indexOf(fileType) >= 0) {
return 'far fa-file-word';
}
// Audio icon
else if (fileType.includes('audio/')) {
return 'far fa-file-audio';
}
// Code files
else if (code.indexOf(fileType) >= 0) {
return 'far fa-file-code';
}

return 'far fa-file';
return 'far fa-file';
}
34 changes: 17 additions & 17 deletions js/src/common/models/File.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@ import Model from 'flarum/common/Model';
import mixin from 'flarum/common/utils/mixin';

export default class File extends mixin(Model, {
baseName: Model.attribute('baseName'),
path: Model.attribute('path'),
url: Model.attribute('url'),
type: Model.attribute('type'),
size: Model.attribute('size'),
humanSize: Model.attribute('humanSize'),
createdAt: Model.attribute('createdAt'),
uuid: Model.attribute('uuid'),
tag: Model.attribute('tag'),
hidden: Model.attribute('hidden'),
bbcode: Model.attribute('bbcode'),
baseName: Model.attribute('baseName'),
path: Model.attribute('path'),
url: Model.attribute('url'),
type: Model.attribute('type'),
size: Model.attribute('size'),
humanSize: Model.attribute('humanSize'),
createdAt: Model.attribute('createdAt'),
uuid: Model.attribute('uuid'),
tag: Model.attribute('tag'),
hidden: Model.attribute('hidden'),
bbcode: Model.attribute('bbcode'),
}) {
/**
* Use FoF Uploads endpoint
*/
apiEndpoint() {
return '/fof/uploads' + (this.exists ? '/' + this.data.id : '');
}
/**
* Use FoF Uploads endpoint
*/
apiEndpoint() {
return '/fof/uploads' + (this.exists ? '/' + this.data.id : '');
}
}
100 changes: 50 additions & 50 deletions js/src/forum/addUploadButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,68 +8,68 @@ import Uploader from './handler/Uploader';
import FileManagerButton from './components/FileManagerButton';

export default function () {
extend(TextEditor.prototype, 'oninit', function () {
this.uploader = new Uploader();
});
extend(TextEditor.prototype, 'controlItems', function (items) {
if (!app.forum.attribute('fof-upload.canUpload')) return;
extend(TextEditor.prototype, 'oninit', function () {
this.uploader = new Uploader();
});
extend(TextEditor.prototype, 'controlItems', function (items) {
if (!app.forum.attribute('fof-upload.canUpload')) return;

const composerButtonVisiblity = app.forum.attribute('fof-upload.composerButtonVisiblity');
const composerButtonVisiblity = app.forum.attribute('fof-upload.composerButtonVisiblity');

// Add media button
if (composerButtonVisiblity === 'both' || composerButtonVisiblity === 'media-btn') {
items.add(
'fof-upload-media',
FileManagerButton.component({
uploader: this.uploader,
})
);
}
// Add media button
if (composerButtonVisiblity === 'both' || composerButtonVisiblity === 'media-btn') {
items.add(
'fof-upload-media',
FileManagerButton.component({
uploader: this.uploader,
})
);
}

// Add upload button
if (composerButtonVisiblity === 'both' || composerButtonVisiblity === 'upload-btn') {
items.add(
'fof-upload',
UploadButton.component({
uploader: this.uploader,
})
);
}
});
// Add upload button
if (composerButtonVisiblity === 'both' || composerButtonVisiblity === 'upload-btn') {
items.add(
'fof-upload',
UploadButton.component({
uploader: this.uploader,
})
);
}
});

extend(TextEditor.prototype, 'oncreate', function (f_, vnode) {
if (!app.forum.attribute('fof-upload.canUpload')) return;
extend(TextEditor.prototype, 'oncreate', function (f_, vnode) {
if (!app.forum.attribute('fof-upload.canUpload')) return;

this.uploader.on('success', ({ file, addBBcode }) => {
if (!addBBcode) return;
this.uploader.on('success', ({ file, addBBcode }) => {
if (!addBBcode) return;

this.attrs.composer.editor.insertAtCursor(file.bbcode() + '\n', false);
this.attrs.composer.editor.insertAtCursor(file.bbcode() + '\n', false);

// We wrap this in a typeof check to prevent it running when a user
// is creating a new discussion. There's nothing to preview in a new
// discussion, so the `preview` function isn't defined.
if (typeof this.attrs.preview === 'function') {
// Scroll the preview into view
// preview() causes the composer to close on mobile, but we don't want that. We want only the scroll
// We work around that by temporarily patching the isFullScreen method
const originalIsFullScreen = app.composer.isFullScreen;
// We wrap this in a typeof check to prevent it running when a user
// is creating a new discussion. There's nothing to preview in a new
// discussion, so the `preview` function isn't defined.
if (typeof this.attrs.preview === 'function') {
// Scroll the preview into view
// preview() causes the composer to close on mobile, but we don't want that. We want only the scroll
// We work around that by temporarily patching the isFullScreen method
const originalIsFullScreen = app.composer.isFullScreen;

app.composer.isFullScreen = () => false;
app.composer.isFullScreen = () => false;

this.attrs.preview();
this.attrs.preview();

app.composer.isFullScreen = originalIsFullScreen;
}
});
app.composer.isFullScreen = originalIsFullScreen;
}
});

this.dragAndDrop = new DragAndDrop((files) => this.uploader.upload(files), this.$().parents('.Composer')[0]);
this.dragAndDrop = new DragAndDrop((files) => this.uploader.upload(files), this.$().parents('.Composer')[0]);

new PasteClipboard((files) => this.uploader.upload(files), this.$('.TextEditor-editor')[0]);
});
new PasteClipboard((files) => this.uploader.upload(files), this.$('.TextEditor-editor')[0]);
});

extend(TextEditor.prototype, 'onremove', function (f_, vnode) {
if (!app.forum.attribute('fof-upload.canUpload')) return;
extend(TextEditor.prototype, 'onremove', function (f_, vnode) {
if (!app.forum.attribute('fof-upload.canUpload')) return;

this.dragAndDrop.unload();
});
this.dragAndDrop.unload();
});
}
Loading

0 comments on commit b7a34a8

Please sign in to comment.