Skip to content
This repository was archived by the owner on Apr 2, 2024. It is now read-only.

Commit 364db4a

Browse files
committed
Add basics but essentials JS utils/mixins
1 parent e31725a commit 364db4a

File tree

10 files changed

+59
-0
lines changed

10 files changed

+59
-0
lines changed

assets/app/mixins/DateMixin.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { formatDate } from '@app/utils/date';
2+
3+
export default {
4+
filters: {
5+
formatDate,
6+
},
7+
methods: {
8+
formatDate,
9+
},
10+
};

assets/app/mixins/RoutingMixin.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { generateRoute } from '@app/utils/route';
2+
3+
export default {
4+
methods: {
5+
path: generateRoute,
6+
},
7+
};

assets/app/mixins/Translatable.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { trans, transChoice } from '@app/utils/translation';
2+
3+
export default {
4+
filters: {
5+
trans,
6+
transChoice,
7+
},
8+
methods: {
9+
trans,
10+
transChoice,
11+
},
12+
};

assets/app/utils/date.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import fr from 'date-fns/locale/fr';
2+
import { format as _format } from 'date-fns';
3+
4+
export const formatDate = (date, format) => _format(date, format, { locale: fr });

assets/app/utils/pagination.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export const makePagination = ({ page = 1, perPage = 20 } = {}) => ({
2+
page,
3+
perPage,
4+
total: -1,
5+
});

assets/app/utils/requestBag.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export const makeRequestBag = ({ data, loading = false } = {}) => ({
2+
data,
3+
loading,
4+
success: null,
5+
successMessage: null,
6+
error: null,
7+
errorMessage: null,
8+
});

assets/app/utils/route.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import Routing from 'routing';
2+
3+
export const generateRoute = (name, params) => Routing.generate(name, params);

assets/app/utils/translation.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import Translator from 'bazinga-translator';
2+
3+
export const trans = (...args) => Translator.trans(...args);
4+
export const transChoice = (...args) => Translator.transChoice(...args);

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"vue-template-compiler": "^2.6.10"
2929
},
3030
"dependencies": {
31+
"date-fns": "^1.30.1",
3132
"jquery": "^3.4.1",
3233
"vue": "^2.6.10"
3334
}

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2162,6 +2162,11 @@ d@1:
21622162
es5-ext "^0.10.50"
21632163
type "^1.0.1"
21642164

2165+
date-fns@^1.30.1:
2166+
version "1.30.1"
2167+
resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-1.30.1.tgz#2e71bf0b119153dbb4cc4e88d9ea5acfb50dc05c"
2168+
integrity sha512-hBSVCvSmWC+QypYObzwGOd9wqdDpOt+0wl0KbU+R+uuZBS1jN8VsD1ss3irQDknRj5NvxiTF6oj/nDRnN/UQNw==
2169+
21652170
date-now@^0.1.4:
21662171
version "0.1.4"
21672172
resolved "https://registry.yarnpkg.com/date-now/-/date-now-0.1.4.tgz#eaf439fd4d4848ad74e5cc7dbef200672b9e345b"

0 commit comments

Comments
 (0)