diff --git a/client/modules/user-menu/index.js b/client/modules/user-menu/index.js index 51931ac1..afc220bd 100644 --- a/client/modules/user-menu/index.js +++ b/client/modules/user-menu/index.js @@ -1,4 +1,3 @@ -/* global CloudCmd, DOM */ import '../../../css/user-menu.css'; import currify from 'currify'; import wraptile from 'wraptile'; @@ -19,6 +18,11 @@ import {runSelected} from './run.js'; const loadCSS = load.css; const sourceStore = fullstore(); +const { + CloudCmd, + DOM, + CloudFunc, +} = globalThis; const Name = 'UserMenu'; CloudCmd[Name] = { @@ -146,6 +150,7 @@ const runUserMenu = async (fn) => { const [error] = await tryToCatch(fn, { DOM, CloudCmd, + CloudFunc, tryToCatch, }); diff --git a/common/cloudfunc.js b/common/cloudfunc.js index a7df97df..0d61cc88 100644 --- a/common/cloudfunc.js +++ b/common/cloudfunc.js @@ -1,17 +1,19 @@ import {rendy} from 'rendy'; import currify from 'currify'; -import store from 'fullstore'; +import {fullstore} from 'fullstore'; import {encode} from '#common/entity'; +const id = (a) => a; + +export const dateFormatter = fullstore(id); + export const getHeaderField = currify(_getHeaderField); -/* КОНСТАНТЫ (общие для клиента и сервера)*/ -/* название программы */ const NAME = 'Cloud Commander'; export const FS = '/fs'; -const Path = store(); +const Path = fullstore(); Path('/'); @@ -123,6 +125,8 @@ export const buildFromJSON = (params) => { showDotFiles, } = params; + const formatDate = dateFormatter(); + const templateFile = template.file; const templateLink = template.link; const json = params.data; @@ -230,7 +234,7 @@ export const buildFromJSON = (params) => { type, name: linkResult, size, - date, + date: formatDate(date), owner, mode, }); @@ -290,3 +294,4 @@ export function getDotDot(path) { return dotDot; } + diff --git a/common/cloudfunc.spec.js b/common/cloudfunc.spec.js index aa50a9f9..c3d3634d 100644 --- a/common/cloudfunc.spec.js +++ b/common/cloudfunc.spec.js @@ -7,6 +7,7 @@ import { getPathLink, buildFromJSON, _getDataName, + dateFormatter, } from '#common/cloudfunc'; const templatePath = new URL('../tmpl/fs', import.meta.url).pathname; @@ -219,3 +220,49 @@ test('cloudfunc: _getDataName', (t) => { t.equal(result, expected); t.end(); }); + +test('cloudfunc: buildFromJSON: formatDate', (t) => { + const data = { + path: '/media/', + files: [{ + date: '30.08.2016', + mode: 'rwx rwx rwx', + name: '{{}}', + owner: 'root', + size: '7b', + type: 'file', + }], + }; + + const oldFormatter = dateFormatter(); + + const formatDate = (str) => { + const [day, month, year] = str.split('.'); + const date = new Date(year, month - 1, day); + + return date.toLocaleDateString(); + }; + + dateFormatter(formatDate); + + const html = buildFromJSON({ + prefix: '', + template, + data, + showDotFiles: false, + }); + + dateFormatter(oldFormatter); + + const $ = cheerio.load(html); + const el = $('[data-name="js-file-JTdCJTdCJTdEJTdE"]'); + + const result = el + .find('[data-name="js-date"]') + .text(); + + const expected = '8/30/2016'; + + t.equal(result, expected); + t.end(); +});