Browse Source

Move humanFileSize and OC.getCanonicalLocale to npm packages

Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Christoph Wurst 3 years ago
parent
commit
eaf4724acc
55 changed files with 27 additions and 161 deletions
  1. 0 0
      apps/files/js/dist/files-app-settings.js
  2. 0 0
      apps/files/js/dist/personal-settings.js
  3. 0 0
      apps/files/js/dist/personal-settings.js.map
  4. 0 0
      apps/files/js/dist/sidebar.js
  5. 0 0
      apps/files/js/dist/sidebar.js.map
  6. 0 0
      apps/files_sharing/js/dist/additionalScripts.js
  7. 0 0
      apps/files_sharing/js/dist/files_sharing_tab.js
  8. 0 0
      apps/files_sharing/js/dist/files_sharing_tab.js.map
  9. 0 0
      apps/files_sharing/js/dist/personal-settings.js
  10. 0 0
      apps/files_sharing/js/dist/personal-settings.js.map
  11. 0 0
      apps/settings/js/vue-0.js
  12. 0 0
      apps/settings/js/vue-0.js.map
  13. 0 0
      apps/settings/js/vue-5.js
  14. 0 0
      apps/settings/js/vue-5.js.map
  15. 0 0
      apps/settings/js/vue-6.js
  16. 0 0
      apps/settings/js/vue-6.js.map
  17. 0 0
      apps/settings/js/vue-7.js
  18. 0 0
      apps/settings/js/vue-7.js.map
  19. 0 0
      apps/settings/js/vue-8.js
  20. 0 0
      apps/settings/js/vue-8.js.map
  21. 0 0
      apps/settings/js/vue-settings-admin-security.js
  22. 0 0
      apps/settings/js/vue-settings-admin-security.js.map
  23. 0 0
      apps/settings/js/vue-settings-apps-users-management.js
  24. 0 0
      apps/settings/js/vue-settings-apps-users-management.js.map
  25. 0 0
      apps/settings/js/vue-settings-personal-security.js
  26. 0 0
      apps/settings/js/vue-settings-personal-security.js.map
  27. 0 0
      apps/settings/js/vue-settings-personal-webauthn.js
  28. 0 0
      apps/settings/js/vue-settings-personal-webauthn.js.map
  29. 0 0
      apps/updatenotification/js/updatenotification.js
  30. 0 0
      apps/updatenotification/js/updatenotification.js.map
  31. 0 0
      apps/workflowengine/js/workflowengine.js
  32. 0 0
      apps/workflowengine/js/workflowengine.js.map
  33. 1 1
      core/js/dist/files_client.js
  34. 0 0
      core/js/dist/files_client.js.map
  35. 0 0
      core/js/dist/files_fileinfo.js
  36. 0 0
      core/js/dist/files_fileinfo.js.map
  37. 0 0
      core/js/dist/files_iedavclient.js
  38. 0 0
      core/js/dist/files_iedavclient.js.map
  39. 1 1
      core/js/dist/install.js
  40. 0 0
      core/js/dist/install.js.map
  41. 1 1
      core/js/dist/login.js
  42. 0 0
      core/js/dist/login.js.map
  43. 1 1
      core/js/dist/main.js
  44. 0 0
      core/js/dist/main.js.map
  45. 1 1
      core/js/dist/maintenance.js
  46. 0 0
      core/js/dist/maintenance.js.map
  47. 0 0
      core/js/dist/recommendedapps.js
  48. 0 0
      core/js/dist/recommendedapps.js.map
  49. 0 88
      core/js/tests/specs/coreSpec.js
  50. 4 2
      core/src/OC/index.js
  51. 0 10
      core/src/OC/l10n.js
  52. 4 1
      core/src/OC/util.js
  53. 0 51
      core/src/Util/human-file-size.js
  54. 12 3
      package-lock.json
  55. 2 1
      package.json

File diff suppressed because it is too large
+ 0 - 0
apps/files/js/dist/files-app-settings.js


File diff suppressed because it is too large
+ 0 - 0
apps/files/js/dist/personal-settings.js


File diff suppressed because it is too large
+ 0 - 0
apps/files/js/dist/personal-settings.js.map


File diff suppressed because it is too large
+ 0 - 0
apps/files/js/dist/sidebar.js


File diff suppressed because it is too large
+ 0 - 0
apps/files/js/dist/sidebar.js.map


File diff suppressed because it is too large
+ 0 - 0
apps/files_sharing/js/dist/additionalScripts.js


File diff suppressed because it is too large
+ 0 - 0
apps/files_sharing/js/dist/files_sharing_tab.js


File diff suppressed because it is too large
+ 0 - 0
apps/files_sharing/js/dist/files_sharing_tab.js.map


File diff suppressed because it is too large
+ 0 - 0
apps/files_sharing/js/dist/personal-settings.js


File diff suppressed because it is too large
+ 0 - 0
apps/files_sharing/js/dist/personal-settings.js.map


File diff suppressed because it is too large
+ 0 - 0
apps/settings/js/vue-0.js


File diff suppressed because it is too large
+ 0 - 0
apps/settings/js/vue-0.js.map


File diff suppressed because it is too large
+ 0 - 0
apps/settings/js/vue-5.js


File diff suppressed because it is too large
+ 0 - 0
apps/settings/js/vue-5.js.map


File diff suppressed because it is too large
+ 0 - 0
apps/settings/js/vue-6.js


File diff suppressed because it is too large
+ 0 - 0
apps/settings/js/vue-6.js.map


File diff suppressed because it is too large
+ 0 - 0
apps/settings/js/vue-7.js


File diff suppressed because it is too large
+ 0 - 0
apps/settings/js/vue-7.js.map


File diff suppressed because it is too large
+ 0 - 0
apps/settings/js/vue-8.js


File diff suppressed because it is too large
+ 0 - 0
apps/settings/js/vue-8.js.map


File diff suppressed because it is too large
+ 0 - 0
apps/settings/js/vue-settings-admin-security.js


File diff suppressed because it is too large
+ 0 - 0
apps/settings/js/vue-settings-admin-security.js.map


File diff suppressed because it is too large
+ 0 - 0
apps/settings/js/vue-settings-apps-users-management.js


File diff suppressed because it is too large
+ 0 - 0
apps/settings/js/vue-settings-apps-users-management.js.map


File diff suppressed because it is too large
+ 0 - 0
apps/settings/js/vue-settings-personal-security.js


File diff suppressed because it is too large
+ 0 - 0
apps/settings/js/vue-settings-personal-security.js.map


File diff suppressed because it is too large
+ 0 - 0
apps/settings/js/vue-settings-personal-webauthn.js


File diff suppressed because it is too large
+ 0 - 0
apps/settings/js/vue-settings-personal-webauthn.js.map


File diff suppressed because it is too large
+ 0 - 0
apps/updatenotification/js/updatenotification.js


File diff suppressed because it is too large
+ 0 - 0
apps/updatenotification/js/updatenotification.js.map


File diff suppressed because it is too large
+ 0 - 0
apps/workflowengine/js/workflowengine.js


File diff suppressed because it is too large
+ 0 - 0
apps/workflowengine/js/workflowengine.js.map


File diff suppressed because it is too large
+ 1 - 1
core/js/dist/files_client.js


File diff suppressed because it is too large
+ 0 - 0
core/js/dist/files_client.js.map


File diff suppressed because it is too large
+ 0 - 0
core/js/dist/files_fileinfo.js


File diff suppressed because it is too large
+ 0 - 0
core/js/dist/files_fileinfo.js.map


File diff suppressed because it is too large
+ 0 - 0
core/js/dist/files_iedavclient.js


File diff suppressed because it is too large
+ 0 - 0
core/js/dist/files_iedavclient.js.map


File diff suppressed because it is too large
+ 1 - 1
core/js/dist/install.js


File diff suppressed because it is too large
+ 0 - 0
core/js/dist/install.js.map


File diff suppressed because it is too large
+ 1 - 1
core/js/dist/login.js


File diff suppressed because it is too large
+ 0 - 0
core/js/dist/login.js.map


File diff suppressed because it is too large
+ 1 - 1
core/js/dist/main.js


File diff suppressed because it is too large
+ 0 - 0
core/js/dist/main.js.map


File diff suppressed because it is too large
+ 1 - 1
core/js/dist/maintenance.js


File diff suppressed because it is too large
+ 0 - 0
core/js/dist/maintenance.js.map


File diff suppressed because it is too large
+ 0 - 0
core/js/dist/recommendedapps.js


File diff suppressed because it is too large
+ 0 - 0
core/js/dist/recommendedapps.js.map


+ 0 - 88
core/js/tests/specs/coreSpec.js

@@ -55,29 +55,6 @@ describe('Core base tests', function() {
 			expect(OC.filePath('files', 'ajax', 'test.php')).toEqual('http://localhost/index.php/apps/files/ajax/test.php');
 		});
 	});
-	describe('getCanonicalLocale', function() {
-		var oldLocale;
-
-		beforeEach(function() {
-			oldLocale = $('html').data('locale')
-		});
-		afterEach(function() {
-			$('html').data('locale', oldLocale)
-		});
-
-		it("Returns primary locales as is", function() {
-			$('html').data('locale', 'de')
-			expect(OC.getCanonicalLocale()).toEqual('de');
-			$('html').data('locale', 'zu')
-			expect(OC.getCanonicalLocale()).toEqual('zu');
-		});
-		it("Returns extended locales with hyphens", function() {
-			$('html').data('locale', 'az_Cyrl_AZ')
-			expect(OC.getCanonicalLocale()).toEqual('az-Cyrl-AZ');
-			$('html').data('locale', 'de_DE')
-			expect(OC.getCanonicalLocale()).toEqual('de-DE');
-		});
-	});
 	describe('Link functions', function() {
 		var TESTAPP = 'testapp';
 		var TESTAPP_ROOT = OC.getRootPath() + '/appsx/testapp';
@@ -364,71 +341,6 @@ describe('Core base tests', function() {
 		});
 	});
 	describe('Util', function() {
-		var locale;
-		var localeStub;
-
-		beforeEach(function() {
-			locale = OC.getCanonicalLocale();
-			localeStub = sinon.stub(OC, 'getCanonicalLocale');
-			localeStub.returns(locale);
-		});
-
-		afterEach(function() {
-			localeStub.restore();
-		});
-
-		describe('humanFileSize', function() {
-			// cit() will skip tests if toLocaleString() is not supported.
-			// See https://github.com/ariya/phantomjs/issues/12581
-			//
-			// Please run these tests in Chrome/Firefox manually.
-			var cit = 4.2.toLocaleString("de") !== "4,2" ? xit : it;
-
-			it('renders file sizes with the correct unit', function() {
-				var data = [
-					[0, '0 B'],
-					["0", '0 B'],
-					["A", 'NaN B'],
-					[125, '125 B'],
-					[128000, '125 KB'],
-					[128000000, '122.1 MB'],
-					[128000000000, '119.2 GB'],
-					[128000000000000, '116.4 TB']
-				];
-				for (var i = 0; i < data.length; i++) {
-					expect(OC.Util.humanFileSize(data[i][0])).toEqual(data[i][1]);
-				}
-			});
-			it('renders file sizes with the correct unit for small sizes', function() {
-				var data = [
-					[0, '0 KB'],
-					[125, '< 1 KB'],
-					[128000, '125 KB'],
-					[128000000, '122.1 MB'],
-					[128000000000, '119.2 GB'],
-					[128000000000000, '116.4 TB']
-				];
-				for (var i = 0; i < data.length; i++) {
-					expect(OC.Util.humanFileSize(data[i][0], true)).toEqual(data[i][1]);
-				}
-			});
-			cit('renders file sizes with the correct locale', function() {
-				localeStub.returns("de");
-				var data = [
-					[0, '0 B'],
-					["0", '0 B'],
-					["A", 'NaN B'],
-					[125, '125 B'],
-					[128000, '125 KB'],
-					[128000000, '122,1 MB'],
-					[128000000000, '119,2 GB'],
-					[128000000000000, '116,4 TB']
-				];
-				for (var i = 0; i < data.length; i++) {
-					expect(OC.Util.humanFileSize(data[i][0])).toEqual(data[i][1]);
-				}
-			});
-		});
 		describe('computerFileSize', function() {
 			it('correctly parses file sizes from a human readable formated string', function() {
 				var data = [

+ 4 - 2
core/src/OC/index.js

@@ -79,10 +79,12 @@ import {
 } from './menu'
 import { isUserAdmin } from './admin'
 import L10N, {
-	getCanonicalLocale,
 	getLanguage,
 	getLocale,
 } from './l10n'
+import {
+	getCanonicalLocale,
+} from '@nextcloud/l10n'
 
 import {
 	generateUrl,
@@ -223,7 +225,7 @@ export default {
 	getProtocol,
 
 	/**
-	 * L10n
+	 * @deprecated 20.0.0 use `getCanonicalLocale` from https://www.npmjs.com/package/@nextcloud/l10n
 	 */
 	getCanonicalLocale,
 	getLocale,

+ 0 - 10
core/src/OC/l10n.js

@@ -323,16 +323,6 @@ const L10n = {
 
 export default L10n
 
-/**
- * Returns the user's locale as a BCP 47 compliant language tag
- *
- * @returns {String} locale string
- */
-export const getCanonicalLocale = () => {
-	const locale = getLocale()
-	return typeof locale === 'string' ? locale.replace(/_/g, '-') : locale
-}
-
 /**
  * Returns the user's locale
  *

+ 4 - 1
core/src/OC/util.js

@@ -24,7 +24,7 @@ import moment from 'moment'
 
 import History from './util-history'
 import OC from './index'
-import humanFileSize from '../Util/human-file-size'
+import { formatFileSize as humanFileSize } from '@nextcloud/files'
 
 function chunkify(t) {
 	// Adapted from http://my.opera.com/GreyWyvern/blog/show.dml/1671288
@@ -58,6 +58,9 @@ export default {
 
 	History,
 
+	/**
+	 * @deprecated use https://nextcloud.github.io/nextcloud-files/modules/_humanfilesize_.html#formatfilesize
+	 */
 	humanFileSize,
 
 	/**

+ 0 - 51
core/src/Util/human-file-size.js

@@ -1,51 +0,0 @@
-/*
- * @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
- *
- * @author 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-/**
- * Returns a human readable file size
- * @param {number} size Size in bytes
- * @param {boolean} skipSmallSizes return '< 1 kB' for small files
- * @returns {string}
- */
-export default function humanFileSize(size, skipSmallSizes) {
-	const humanList = ['B', 'KB', 'MB', 'GB', 'TB']
-	// Calculate Log with base 1024: size = 1024 ** order
-	let order = size > 0 ? Math.floor(Math.log(size) / Math.log(1024)) : 0
-	// Stay in range of the byte sizes that are defined
-	order = Math.min(humanList.length - 1, order)
-	const readableFormat = humanList[order]
-	let relativeSize = (size / Math.pow(1024, order)).toFixed(1)
-	if (skipSmallSizes === true && order === 0) {
-		if (relativeSize !== '0.0') {
-			return '< 1 KB'
-		} else {
-			return '0 KB'
-		}
-	}
-	if (order < 2) {
-		relativeSize = parseFloat(relativeSize).toFixed(0)
-	} else if (relativeSize.substr(relativeSize.length - 2, 2) === '.0') {
-		relativeSize = relativeSize.substr(0, relativeSize.length - 2)
-	} else {
-		relativeSize = parseFloat(relativeSize).toLocaleString(OC.getCanonicalLocale())
-	}
-	return relativeSize + ' ' + readableFormat
-}

+ 12 - 3
package-lock.json

@@ -3214,6 +3214,15 @@
         }
       }
     },
+    "@nextcloud/files": {
+      "version": "1.1.0",
+      "resolved": "https://registry.npmjs.org/@nextcloud/files/-/files-1.1.0.tgz",
+      "integrity": "sha512-wBtgtE3cSII5dNBOSIbkEHlroOGHS34CI7P20ye/9RYBY3TuKakhw5loT68wEOXa29Sp7GZsdWOuzxoRlsF2GA==",
+      "requires": {
+        "@nextcloud/l10n": "^1.3.0",
+        "core-js": "^3.6.4"
+      }
+    },
     "@nextcloud/initial-state": {
       "version": "1.1.2",
       "resolved": "https://registry.npmjs.org/@nextcloud/initial-state/-/initial-state-1.1.2.tgz",
@@ -3223,9 +3232,9 @@
       }
     },
     "@nextcloud/l10n": {
-      "version": "1.2.3",
-      "resolved": "https://registry.npmjs.org/@nextcloud/l10n/-/l10n-1.2.3.tgz",
-      "integrity": "sha512-bd/bp/pk24Sl/Fjj3KJhDsGhc5EI1tIs34+sl4eaBNrj7SHl79K9bAzarxtABx6LSXn6pl6K/YYkKCidqPzuDQ==",
+      "version": "1.3.0",
+      "resolved": "https://registry.npmjs.org/@nextcloud/l10n/-/l10n-1.3.0.tgz",
+      "integrity": "sha512-hGk3ag9TU4cb0+ld/wziEsE+CWaS7Rpj6Y6dPv0QVfnqQ7jFCKQ62VHnuk8pFQHkmKMg3HGxkHuojumbukm42w==",
       "requires": {
         "core-js": "^3.6.4",
         "node-gettext": "^3.0.0"

+ 2 - 1
package.json

@@ -31,8 +31,9 @@
     "@nextcloud/capabilities": "^1.0.2",
     "@nextcloud/dialogs": "^1.3.1",
     "@nextcloud/event-bus": "^1.1.4",
+    "@nextcloud/files": "^1.1.0",
     "@nextcloud/initial-state": "^1.1.2",
-    "@nextcloud/l10n": "^1.2.3",
+    "@nextcloud/l10n": "^1.3.0",
     "@nextcloud/logger": "^1.1.2",
     "@nextcloud/password-confirmation": "^1.0.1",
     "@nextcloud/paths": "^1.1.2",

Some files were not shown because too many files changed in this diff