Enhance core API

- Add trim function to core API
- Minor bug fix
This commit is contained in:
lxsang 2020-06-06 18:41:43 +02:00
parent 598c11b2c3
commit edbffeb2b8
4 changed files with 42 additions and 41 deletions

View File

@ -43,6 +43,9 @@ interface String {
f(...args: any[]): OS.FormatedString; f(...args: any[]): OS.FormatedString;
__(): string; __(): string;
l(): string; l(): string;
trimLeft(arg: string): string;
trimRight(arg: string): string;
trimBy(arg: string): string;
} }
/** /**
@ -378,8 +381,7 @@ namespace OS {
Object.defineProperty(Object.prototype, "__", { Object.defineProperty(Object.prototype, "__", {
value() { value() {
if(this) if (this) return this.toString();
return this.toString();
}, },
enumerable: false, enumerable: false,
writable: true, writable: true,
@ -459,7 +461,20 @@ namespace OS {
} }
return API.lang[this]; return API.lang[this];
}; };
String.prototype.trimLeft = function (charlist: string): string {
if (charlist === undefined) charlist = "s";
return this.replace(new RegExp("^[" + charlist + "]+"), "");
};
String.prototype.trimRight = function (charlist: string): string {
if (charlist === undefined) charlist = "s";
return this.replace(new RegExp("[" + charlist + "]+$"), "");
};
String.prototype.trimBy = function (charlist: string) {
return this.trimLeft(charlist).trimRight(charlist);
};
Date.prototype.toString = function (): string { Date.prototype.toString = function (): string {
let dd = this.getDate(); let dd = this.getDate();
let mm = this.getMonth() + 1; let mm = this.getMonth() + 1;
@ -490,7 +505,7 @@ namespace OS {
return (this.getTime() / 1000) | 0; return (this.getTime() / 1000) | 0;
}; };
export const VERSION:Version = "1.0.0-a".__v(); export const VERSION: Version = "1.0.0-a".__v();
/** /**
* *
* *
@ -500,10 +515,10 @@ namespace OS {
* @returns {*} * @returns {*}
*/ */
export function register(name: string, x: PM.ProcessTypeClass): void { export function register(name: string, x: PM.ProcessTypeClass): void {
if ((x as any as typeof BaseModel).type === ModelType.SubWindow) { if (((x as any) as typeof BaseModel).type === ModelType.SubWindow) {
GUI.dialog[name] = x; GUI.dialog[name] = x;
} else { } else {
(application[name] = x); application[name] = x;
} }
} }
@ -573,9 +588,7 @@ namespace OS {
.setting() .setting()
.then(function (r: any) { .then(function (r: any) {
cleanup(); cleanup();
return API.handle return API.handle.logout().then((d: any) => boot());
.logout()
.then((d: any) => boot());
}) })
.catch((e: Error) => console.error(e)); .catch((e: Error) => console.error(e));
} }
@ -625,7 +638,6 @@ namespace OS {
export var lang: GenericObject<string> = {}; export var lang: GenericObject<string> = {};
/** /**
* *
* *
@ -695,9 +707,7 @@ namespace OS {
resolve(this.response); resolve(this.response);
} else { } else {
API.loaded(q, p, "FAIL"); API.loaded(q, p, "FAIL");
reject( reject(API.throwe(__("Unable to get blob: {0}", p)));
API.throwe(__("Unable to get blob: {0}", p))
);
} }
}; };
API.loading(q, p); API.loading(q, p);
@ -887,10 +897,7 @@ namespace OS {
}).appendTo("head"); }).appendTo("head");
API.shared[l] = true; API.shared[l] = true;
console.log("Loaded :", l); console.log("Loaded :", l);
announcer.trigger( announcer.trigger("sharedlibraryloaded", l);
"sharedlibraryloaded",
l
);
return resolve(undefined); return resolve(undefined);
}) })
.catch((e: Error) => reject(__e(e))); .catch((e: Error) => reject(__e(e)));
@ -899,10 +906,7 @@ namespace OS {
.then(function (data: any) { .then(function (data: any) {
API.shared[l] = true; API.shared[l] = true;
console.log("Loaded :", l); console.log("Loaded :", l);
announcer.trigger( announcer.trigger("sharedlibraryloaded", l);
"sharedlibraryloaded",
l
);
return resolve(data); return resolve(data);
}) })
.catch((e: Error) => reject(__e(e))); .catch((e: Error) => reject(__e(e)));
@ -931,22 +935,18 @@ namespace OS {
if (!(libs.length > 0)) { if (!(libs.length > 0)) {
return resolve(); return resolve();
} }
announcer.observable.one( announcer.observable.one("sharedlibraryloaded", function (l) {
"sharedlibraryloaded",
function (l) {
libs.splice(0, 1); libs.splice(0, 1);
return API.require(libs) return API.require(libs)
.catch((e: Error) => reject(__e(e))) .catch((e: Error) => reject(__e(e)))
.then((r: any) => resolve(r)); .then((r: any) => resolve(r));
} });
);
return API.requires(libs[0]).catch((e: Error) => return API.requires(libs[0]).catch((e: Error) =>
reject(__e(e)) reject(__e(e))
); );
}); });
} }
export namespace packages { export namespace packages {
/** /**
* *
* *
@ -992,7 +992,6 @@ namespace OS {
} }
} }
/** /**
* *
* *

View File

@ -668,6 +668,7 @@ namespace OS {
* @memberof TreeViewTag * @memberof TreeViewTag
*/ */
set data(v: TreeViewDataType) { set data(v: TreeViewDataType) {
this._selectedItem = undefined
if (!v) { if (!v) {
return; return;
} }

View File

@ -1147,10 +1147,7 @@ namespace OS {
*/ */
_rd(t: string): Promise<any> { _rd(t: string): Promise<any> {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
return resolve({ return resolve(this.cache);
result: this.cache,
error: false,
});
}); });
} }

View File

@ -169,7 +169,7 @@ namespace OS {
// copy file // copy file
return file return file
.read("binary") .read("binary")
.then(async (data: BlobPart) => { .then(async (data: ArrayBuffer) => {
const d = await tof const d = await tof
.setCache( .setCache(
new Blob([data], { new Blob([data], {
@ -246,15 +246,19 @@ namespace OS {
} else { } else {
return file return file
.read("binary") .read("binary")
.then((d: any) => { .then(async (d: any) => {
const zpath = `${base}${file.basename}`.replace( const zpath = `${base}${file.basename}`.replace(
/^\/+|\/+$/g, /^\/+|\/+$/g,
"" ""
); );
zip.file(zpath, d, { binary: true }); zip.file(zpath, d, { binary: true });
return this.aradd(list, zip, base) try {
.then(() => resolve(zip)) await this.aradd(list, zip, base);
.catch((e) => reject(__e(e))); return resolve(zip);
}
catch (e) {
return reject(__e(e));
}
}) })
.catch((e: Error) => reject(__e(e))); .catch((e: Error) => reject(__e(e)));
} }