Skip to content

Commit d14e543

Browse files
committed
fix VuetifyGenerator
1 parent 968b70d commit d14e543

File tree

4 files changed

+76
-22
lines changed

4 files changed

+76
-22
lines changed

src/generators/VuetifyGenerator.js

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,6 @@ export default class extends BaseVueGenerator {
4444
);
4545
console.log(
4646
chalk.green(`
47-
//Configure your Vuetify plugin
48-
// src/plugins/vuetify.js
49-
50-
import Vue from 'vue'
51-
import Vuetify from 'vuetify/lib'
52-
53-
Vue.use(Vuetify)
54-
55-
const opts = {
56-
icons: {
57-
iconfont: 'mdi'
58-
}
59-
};
60-
61-
export default new Vuetify(opts)
62-
6347
// Register the routes in you router
6448
// src/router/index.js
6549
import ${titleLc}Routes from './${titleLc}';
@@ -74,7 +58,7 @@ export default new VueRouter({
7458
7559
// Register the modules in the store
7660
// src/store/index.js
77-
import ${titleLc}Service from './services/${titleLc}';
61+
import ${titleLc}Service from '../services/${titleLc}';
7862
import makeCrudModule from './modules/crud';
7963
8064
// ...
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import { Api, Resource, Field } from "@api-platform/api-doc-parser";
2+
import fs from "fs";
3+
import tmp from "tmp";
4+
import VuetifyGenerator from "./VuetifyGenerator";
5+
6+
test("Generate a Vuetify app", () => {
7+
const generator = new VuetifyGenerator({
8+
hydraPrefix: "hydra:",
9+
templateDirectory: `${__dirname}/../../templates`
10+
});
11+
const tmpobj = tmp.dirSync({ unsafeCleanup: true });
12+
13+
const fields = [
14+
new Field("bar", {
15+
id: "http://schema.org/url",
16+
range: "http://www.w3.org/2001/XMLSchema#string",
17+
reference: null,
18+
required: true,
19+
description: "An URL"
20+
})
21+
];
22+
const resource = new Resource("abc", "http://example.com/foos", {
23+
id: "foo",
24+
title: "Foo",
25+
readableFields: fields,
26+
writableFields: fields,
27+
getParameters: function getParameters() {
28+
return Promise.resolve([]);
29+
}
30+
});
31+
const api = new Api("http://example.com", {
32+
entrypoint: "http://example.com:8080",
33+
title: "My API",
34+
resources: [resource]
35+
});
36+
generator.generate(api, resource, tmpobj.name).then(() => {
37+
[
38+
"/components/ActionCell",
39+
"/components/Breadcrumb",
40+
"/components/ConfirmDelete",
41+
"/components/DataFilter",
42+
"/components/foo/Filter",
43+
"/components/foo/Form.vue",
44+
"/components/foo/Layout",
45+
"/components/InputDate.vue",
46+
"/components/Loading.vue",
47+
"/components/Snackbar.vue",
48+
"/components/Toolbar.vue",
49+
"/config/entrypoint.js",
50+
"/error/SubmissionError.js",
51+
"/locales/en.js",
52+
"/router/foo.js",
53+
"/services/api.js",
54+
"/services/foo.js",
55+
"/utils/dates.js",
56+
"/utils/fetch.js",
57+
"/utils/hydra.js",
58+
"/views/foo/Create.vue",
59+
"/views/foo/List.vue",
60+
"/views/foo/Show.vue",
61+
"/views/foo/Update.vue"
62+
].forEach(file => expect(fs.existsSync(tmpobj.name + file)).toBe(true));
63+
64+
tmpobj.removeCallback();
65+
});
66+
});

templates/vue-common/mixins/ListMixin.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import isEmpty from 'lodash/isEmpty';
12
import { formatDateTime } from '../utils/dates';
23
import NotificationMixin from './NotificationMixin';
34

@@ -39,7 +40,8 @@ export default {
3940
if (itemsPerPage > 0) {
4041
params = { ...params, itemsPerPage, page };
4142
}
42-
if (sortBy) {
43+
44+
if (!isEmpty(sortBy)) {
4345
params[`order[${sortBy}]`] = descending ? 'desc' : 'asc';
4446
}
4547

templates/vuetify/views/foo/List.vue

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,17 @@
5151
{{/case~}}
5252
{{#default}}
5353
{{#if reference}}
54-
{{#unless maxCardinality}}
5554
<template slot="item.{{{name}}}" slot-scope="{ item }">
55+
{{#if maxCardinality }}
56+
\{{ item['@id'] }}
57+
{{else}}
5658
<ul>
57-
<li v-for="_item in item['{{{name}}}']" :key="_item.id">
58-
\{{ _item.id }}
59+
<li v-for="_item in item['{{{name}}}']" :key="_item['@id']">
60+
\{{ _item['@id'] }}
5961
</li>
6062
</ul>
63+
{{/if}}
6164
</template>
62-
{{/unless~}}
6365
{{/if~}}
6466
{{/default~}}
6567
{{/switch}}

0 commit comments

Comments
 (0)