Skip to content

Commit

Permalink
Initial commit of rewrite of client-side JS.
Browse files Browse the repository at this point in the history
Summary:
– Add Svelte support, rollup config, babel, prettier
– Update eslint config
– Add Editor & Viewer Svelte components
– Add Linkeditor Service to handle integrations
– Rename sanitizeUrl lib and use ES6 exports
  • Loading branch information
te-online committed May 12, 2020
1 parent 69cc9c8 commit 88a2e34
Show file tree
Hide file tree
Showing 17 changed files with 6,260 additions and 222 deletions.
16 changes: 16 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"presets": [
[
"@babel/preset-env",
{
"targets": "> 0.25%, not dead, edge >= 12, safari >= 9",
"useBuiltIns": "usage",
"corejs": "3"
}
]
],
"plugins": [
"@babel/plugin-transform-classes",
"@babel/plugin-transform-async-to-generator"
]
}
34 changes: 7 additions & 27 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,13 @@
"OCA": true,
"$": true
},
"env": {
"es6": false,
"node": false,
"browser": true
},
"extends": "eslint:recommended",
"parserOptions": {
"sourceType": "module"
},
"extends": [
"standard",
"prettier",
"plugin:prettier/recommended"
],
"rules": {
"indent": [
"warn",
"tab"
],
"linebreak-style": [
"warn",
"unix"
],
"quotes": [
"warn",
"single"
],
"no-console": [
"warn"
],
"no-redeclare": [
"off"
]
"dot-notation": "off",
"camelcase": "off"
}
}
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"printWidth": 120,
"braceStyle": "1tbs",
"tabWidth": 2,
"useTabs": true
}
2 changes: 1 addition & 1 deletion css/merged.scss
Original file line number Diff line number Diff line change
@@ -1 +1 @@
@import 'linkeditor.scss';
@import 'linkeditor.scss';
194 changes: 194 additions & 0 deletions js/Linkeditor.service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
import { sanitizeUrl } from "./sanitizeUrl";

export class LinkeditorService {
/**
* Registers the file actions
*/
static registerFileActions() {
const mimes = LinkeditorService.getSupportedMimetypes();

mimes.forEach((value) => {
window.OCA.Files.fileActions.registerAction({
name: "editLink",
displayName: t("files_linkeditor", "Edit link"),
mime: value,
// @TODO:
actionHandler: (something) => {
console.log({ edit: true, something });
},
permissions: window.OC.PERMISSION_UPDATE,
iconClass: "icon-link",
});

window.OCA.Files.fileActions.registerAction({
name: "viewLink",
displayName: t("files_linkeditor", "View link"),
mime: value,
actionHandler: (filename, context) => {
window.context = context;
// Build the download url.
const downloadUrl = context.fileList.getDownloadUrl(filename);
// Find out where we are to use this link for the cancel button.
const currentUrl = encodeURI(context.fileList.linkTo() + "?path=" + context.dir);
// Find the element we are clicking on.
const linkElement = document.querySelector('[href="' + downloadUrl + '"]');
// Trigger view Action
// @TODO:
console.log({
view: true,
filename,
downloadUrl,
currentUrl,
linkElement,
});
},
permissions: window.OC.PERMISSION_READ,
iconClass: "icon-link",
});

// Use Link viewing as default action.
window.OCA.Files.fileActions.setDefault(value, "viewLink");
});

window.OC.Plugins.register("OCA.Files.NewFileMenu", {
attach: function (menu) {
const fileList = menu.fileList;

// Only attach to main file list
if (fileList.id !== "files") {
return;
}

// Register the new menu entry
menu.addMenuEntry({
id: "application-internet-shortcut",
displayName: window.t("files_linkeditor", "New link"),
templateName: window.t("files_linkeditor", "Link.URL"),
iconClass: "icon-link",
fileType: "application/internet-shortcut",
actionHandler: function (name) {
const dir = fileList.getCurrentDirectory();
// First create the file
fileList
.createFile(name, {
scrollTo: false,
})
.then(function () {
// once the file got successfully created,
// open the editor
// @TODO:
console.log({
new: true,
fileList: fileList,
dir: dir,
name,
});
});
},
});
},
});
}

static getSupportedMimetypes() {
return ["application/internet-shortcut"];
}

static encodeURI() {}

/**
* Generates a URL file.
*/
static generateURLFileContent(oldcontent, url) {
// Find if this is already a shortcut file.
if (oldcontent && oldcontent.indexOf("[InternetShortcut]") !== -1 && oldcontent.indexOf("URL=") !== -1) {
// Seems like it, replace the url.
return oldcontent.replace(new RegExp("URL=.*", "gm"), "URL=" + sanitizeUrl(url));
} else {
// Okay, let's create a new file.
return "[InternetShortcut]\r\nURL=" + sanitizeUrl(url) + "\r\n";
}
}

/**
* Parse a URL file.
*/
static parseURLFile(filecontent) {
if (filecontent) {
// Match for URL line.
var urllines = filecontent.match("URL=.*");
// See if matches were found.
if (urllines && Array.isArray(urllines) && urllines.length > 0) {
// Let's use the first match.
var url = urllines[0];
// Return only the URL.
return sanitizeUrl(url.replace("URL=", ""));
}
}
return "";
}

/**
* Generates a webloc file.
*/
static generateWeblocFileContent(oldcontent, url) {
// Find if this is already a shortcut file.
// Match for URL line.
var urlmatch = oldcontent.match("<key>URL</key>\n.<string>(.*)</string>");
// See if at least two matches were found (the whole expression and the url itself).
if (urlmatch && Array.isArray(urlmatch) && urlmatch.length > 1) {
// Seems like it, replace the url.
return oldcontent.replace(urlmatch[1], sanitizeUrl(url));
} else {
// Okay, let's create a new file.
return (
'<?xml version="1.0" encoding="UTF-8"?>\n' +
'<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">\n' +
'<plist version="1.0">\n' +
" <dict>\n" +
" <key>URL</key>\n" +
" <string>" +
sanitizeUrl(url) +
"</string>\n" +
" </dict>\n" +
"</plist>"
);
}
}

/**
* Parse a webloc file.
*/
static parseWeblocFile(filecontent) {
if (filecontent) {
// Match for URL line.
var urlmatch = filecontent.match("<key>URL</key>\n.<string>(.*)</string>");
// See if at least two matches were found (the whole expression and the url itself).
if (urlmatch && Array.isArray(urlmatch) && urlmatch.length > 1) {
// Let's use the first match.
return sanitizeUrl(urlmatch[1]);
}
}
return "";
}

/**
* Get extension from filename.
*/
static getExtension(filename) {
if (filename) {
// Split at dot.
var parts = filename.split(".");
// See if there was a dot in the name.
if (parts && Array.isArray(parts) && parts.length > 1) {
// Get extension.
var extension = parts[parts.length - 1];
// Return the last part after the last dot.
if (extension) {
return extension.toLowerCase();
}
}
}
return "";
}
}
Loading

0 comments on commit 88a2e34

Please sign in to comment.