Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable linting for several vue-components files #1299

Merged
merged 1 commit into from
Aug 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,11 @@ packages/vue-components/src/utils/utils.js
# yuche/vue-strap
packages/vue-components/src/Affix.vue
packages/vue-components/src/Dropdown.vue
packages/vue-components/src/index.js
packages/vue-components/src/main.js
packages/vue-components/src/Navbar.vue
packages/vue-components/src/Panel.vue
packages/vue-components/src/Tab.vue
packages/vue-components/src/TabGroup.vue
packages/vue-components/src/Tabset.vue
packages/vue-components/src/Typeahead.vue

# MarkBind/vue-strap
packages/vue-components/src/panels/MinimalPanel.vue
packages/vue-components/src/panels/NestedPanel.vue
packages/vue-components/src/panels/PanelBase.js
packages/vue-components/src/panels/PanelSwitch.vue
packages/vue-components/src/Pic.vue
packages/vue-components/src/Retriever.vue
packages/vue-components/src/Thumbnail.vue

# --- packages/vue-components end ---
4 changes: 4 additions & 0 deletions packages/vue-components/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ module.exports = {
'../../.eslintrc.js',
'plugin:vue/recommended',
],
'globals': {
'jQuery': 'readonly',
'Vue': 'readonly',
},
'rules': {
'quote-props': 'off',
'vue/html-self-closing': [
Expand Down
34 changes: 19 additions & 15 deletions packages/vue-components/src/Panel.vue
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
<template>
<minimal-panel v-if="isMinimal" v-bind="$attrs">
<template v-for="(node, name) in $slots" :slot="name">
<slot :name="name"></slot>
</template>
</minimal-panel>
<nested-panel v-else :type="type" v-bind="$attrs">
<template v-for="(node, name) in $slots" :slot="name">
<slot :name="name"></slot>
</template>
</nested-panel>
<minimal-panel v-if="isMinimal" v-bind="$attrs">
<template v-for="(node, name) in $slots" :slot="name">
<slot :name="name"></slot>
</template>
</minimal-panel>
<nested-panel
v-else
:type="type"
v-bind="$attrs"
>
<template v-for="(node, name) in $slots" :slot="name">
<slot :name="name"></slot>
</template>
</nested-panel>
</template>

<script>
import nestedPanel from "./panels/NestedPanel.vue";
import minimalPanel from "./panels/MinimalPanel.vue";
import nestedPanel from './panels/NestedPanel.vue';
import minimalPanel from './panels/MinimalPanel.vue';

export default {
components: {
Expand All @@ -29,7 +33,7 @@ export default {
computed: {
isMinimal() {
return this.type === 'minimal';
}
}
}
},
},
};
</script>
115 changes: 62 additions & 53 deletions packages/vue-components/src/Pic.vue
Original file line number Diff line number Diff line change
@@ -1,67 +1,76 @@
<template>
<div :class="['image-wrapper', addClass]">
<img ref="pic" @load.once="computeWidth" :src="src" :alt="alt" :width="computedWidth" class="img-fluid rounded">
<div class="image-caption">
<slot></slot>
</div>
<div :class="['image-wrapper', addClass]">
<img
ref="pic"
:src="src"
:alt="alt"
:width="computedWidth"
class="img-fluid rounded"
@load.once="computeWidth"
/>
<div class="image-caption">
<slot></slot>
</div>
</div>
</template>

<script>
import {toNumber} from './utils/utils.js'
import { toNumber } from './utils/utils';

export default {
props: {
src: {
type: String
},
alt: {
type: String
},
height: {
type: String,
default: ''
},
width: {
type: String,
default: ''
},
addClass: {
type: String,
default: ''
}
export default {
props: {
src: {
type: String,
default: null,
},
computed: {
hasWidth () {
return this.width !== '';
},
hasHeight () {
return this.height !== '';
},
computedWidth () {
if (this.hasWidth) {
return this.width;
}
return this.widthFromHeight;
}
alt: {
type: String,
default: null,
},
height: {
type: String,
default: '',
},
width: {
type: String,
default: '',
},
addClass: {
type: String,
default: '',
},
data () {
return {
widthFromHeight: '',
},
computed: {
hasWidth() {
return this.width !== '';
},
hasHeight() {
return this.height !== '';
},
computedWidth() {
if (this.hasWidth) {
return this.width;
}
return this.widthFromHeight;
},
methods: {
computeWidth() {
if (!this.hasWidth && this.hasHeight) {
const renderedImg = this.$refs.pic;
const imgHeight = renderedImg.naturalHeight;
const imgWidth = renderedImg.naturalWidth;
const aspectRatio = imgWidth / imgHeight;
this.widthFromHeight = Math.round(toNumber(this.height) * aspectRatio).toString();
}
},
data() {
return {
widthFromHeight: '',
};
},
methods: {
computeWidth() {
if (!this.hasWidth && this.hasHeight) {
const renderedImg = this.$refs.pic;
const imgHeight = renderedImg.naturalHeight;
const imgWidth = renderedImg.naturalWidth;
const aspectRatio = imgWidth / imgHeight;
this.widthFromHeight = Math.round(toNumber(this.height) * aspectRatio).toString();
}
}
}
},
},
};
</script>

<style>
Expand Down
82 changes: 44 additions & 38 deletions packages/vue-components/src/Retriever.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,85 +5,91 @@
</template>

<script>
import {getFragmentByHash, toBoolean} from './utils/utils.js'
import { getFragmentByHash, toBoolean } from './utils/utils';

export default {
props: {
src: {
type: String
type: String,
default: null,
},
fragment: {
type: String // fragment identified (the '#' in URI)
type: String, // fragment identified (the '#' in URI)
default: null,
},
delay: {
type: Boolean,
default: false
default: false,
},
_hasFetched: {
hasFetched: {
type: Boolean,
default: false
}
default: false,
},
},
computed: {
// Vue 2.0 coerce migration
delayBool () {
delayBool() {
return toBoolean(this.delay);
}
},
// Vue 2.0 coerce migration end
},
methods: {
fetch() {
if (!this.src) {
return;
}
if (this._hasFetched) {
if (this.hasFetched) {
return;
}
jQuery.get(this.src)
.done((response) => {
var result = response;
let result = response;
if (this.fragment) {
var tempDom = jQuery('<temp>').append(jQuery.parseHTML(result));
var appContainer = jQuery('#' + this.fragment, tempDom);
const tempDom = jQuery('<temp>').append(jQuery.parseHTML(result));
const appContainer = jQuery(`#${this.fragment}`, tempDom);
result = appContainer.html();
}
this._hasFetched = true
this.hasFetched = true;
// result is empty / undefined
if (result == void(0) && this.fragment) {
this.$el.innerHTML = `<strong>Error</strong>: Failed to retrieve page fragment: ${this.src}#${this.fragment}`
return
if (result === undefined && this.fragment) {
this.$el.innerHTML
= `<strong>Error</strong>: Failed to retrieve page fragment: ${this.src}#${this.fragment}`;
return;
}

// Mount result in retriever
let tempComponent = Vue.extend({
const TempComponent = Vue.extend({
template: `<div>\n${result}\n</div>`,
})
new tempComponent().$mount(this.$el);
});
new TempComponent().$mount(this.$el);
this.$emit('src-loaded');
})
.fail((error) => {
console.error(error.responseText)
this.$el.innerHTML = `<strong>Error</strong>: Failed to retrieve content from source: <em>${this.src}</em>`
// eslint-disable-next-line no-console
console.error(error.responseText);
this.$el.innerHTML
= `<strong>Error</strong>: Failed to retrieve content from source: <em>${this.src}</em>`;
this.$emit('src-loaded');
});
}
},
},
mounted() {
this.$nextTick( function () {
if (!this.src) {
this.$el.innerHTML = ''
} else {
var hash = getFragmentByHash(this.src)
if (hash) {
this.fragment = hash
this.src = this.src.split('#')[0];
}
this.$nextTick(function () {
if (!this.src) {
this.$el.innerHTML = '';
} else {
const hash = getFragmentByHash(this.src);
if (hash) {
this.fragment = hash;
// eslint-disable-next-line prefer-destructuring
this.src = this.src.split('#')[0];
}
}

if (!this.delayBool) {
this.fetch();
}
})
}
}
if (!this.delayBool) {
this.fetch();
}
});
},
};
</script>
Loading