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

WIP: Implement one Vue component #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
7 changes: 7 additions & 0 deletions dev/webpack.base.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ exports['default'] = new Config().merge({
publicPath: '/'
},
resolve: {
extensions: ['.js', '.vue'],
modules: [
'node_modules',
join(ROOT, 'http'),
Expand All @@ -36,6 +37,7 @@ exports['default'] = new Config().merge({
alias: {
'/template': 'template',
'/images': 'iznik-client/images',
'vue': 'vue/dist/vue.runtime.common',
...shims.aliases
}
},
Expand All @@ -51,6 +53,11 @@ exports['default'] = new Config().merge({
exclude: /(node_modules|js(\/|\\)lib)/,
use: 'babel-loader'
},
{
test: /\.vue$/,
exclude: /(node_modules|js\/lib)/,
loader: 'vue-loader'
},
{
test: /\.(png|jpeg|jpg|gif|woff|woff2|ttf|eot|svg)$/,
use: [{loader: 'url-loader', options: {limit: 8192}}]
Expand Down
33 changes: 32 additions & 1 deletion http/js/iznik/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ define([
'backbone',
'underscore',
'moment',
'vue',
'backbone.collectionView',
'dateshim',
'bootstrap',
Expand All @@ -25,7 +26,7 @@ define([
'iznik/events',
'iznik/timeago',
'iznik/majax'
], function ($, Backbone, _, moment) {
], function ($, Backbone, _, moment, Vue) {
// Promise polyfill for older browsers or IE11 which has less excuse.
if (typeof window.Promise !== 'function') {
require('es6-promise').polyfill();
Expand Down Expand Up @@ -1003,6 +1004,36 @@ define([
}
});

Iznik.VueView = Iznik.View.extend({
render: function(){
var self = this;
var vueEl = document.createElement('span');
self.$el.append(vueEl);
var on = _.mapObject(self.vueEvents, function(methodName){
return self[methodName].bind(self);
});
return Promise.resolve(self.component).then(function(Component){
if (Component.default) Component = Component.default;
new Vue({
el: vueEl,
data: self.model.toJSON(),
created: function () {
var vm = this;
self.model.on('change', function() {
Object.assign(vm, self.model.toJSON());
});
},
render: function(h) {
return h(Component, {
props: this.$data,
on: on
})
}
});
});
}
});

// Save as global as it's useful for debugging.
window.Iznik = Iznik;

Expand Down
29 changes: 7 additions & 22 deletions http/js/iznik/views/group/volunteering.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ define([
'underscore',
'backbone',
'iznik/base',
'/template/volunteering/one',
'moment',
'combodate',
'jquery.validate.min',
'jquery.validate.additional-methods',
'iznik/models/volunteering',
'iznik/views/group/select',
'iznik/customvalidate'
], function($, _, Backbone, Iznik, moment) {
], function($, _, Backbone, Iznik, VolunteeringOne, moment) {
Iznik.Views.User.VolunteeringSidebar = Iznik.View.extend({
template: "volunteering_list",

Expand Down Expand Up @@ -96,14 +97,14 @@ define([
}
});

Iznik.Views.User.Volunteering = Iznik.View.extend({
Iznik.Views.User.Volunteering = Iznik.VueView.extend({
tagName: 'li',

template: "volunteering_one",
className: 'padleftsm',
component: VolunteeringOne,
className: 'padleftsm completefull',

events: {
'click .js-info': 'info'
vueEvents: {
info: 'info'
},

info: function() {
Expand All @@ -123,22 +124,6 @@ define([
v.render();
});
},

render: function() {
var self = this;

var desc = self.model.get('description');
if (desc && desc.length > 100) {
self.model.set('description', desc.substring(0, 100) + '...');
}

var p = Iznik.View.prototype.render.call(this).then(function() {
self.$el.closest('li').addClass('completefull');
self.model.on('change', self.render, self);
});

return(p);
}
});

Iznik.Views.User.Volunteering.Details = Iznik.Views.Modal.extend({
Expand Down
28 changes: 0 additions & 28 deletions http/template/volunteering/one.html

This file was deleted.

60 changes: 60 additions & 0 deletions http/template/volunteering/one.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<template>
<div class="panel panel-info">
<div class="panel-heading">
{{title}}
</div>
<div class="panel-body nopadtop">
<div class="row">
<div class="col-xs-12">
<div class="glyphicons glyphicons-info-sign inline" /><div class="inline padleft js-description">{{cappedDescription}}</div>
</div>
</div>
<div class="row">
<div class="col-xs-12">
<div class="glyphicons glyphicons-map-marker inline" /><div class="inline padleft">{{location}}</div>
</div>
<hr class="nomargin"/>
</div>
<div class="row text-center">
<div class="col-xs-12">
<button @click="$emit('info')" class="js-info btn btn-white"><div class="glyphicon glyphicon-info-sign inline" /><div class="inline padleft">More info</div></button>
</div>
</div>
<div class="row">
<div v-if="groups.length > 0" class="topspace text-muted small text-center">Posted on {{groups[0].namedisplay}}</div>
</div>
</div>
</div>
</template>

<script>
export default {
props: {
title: {
required: true,
type: String
},
description: {
required: true,
type: String
},
location: {
required: true,
type: String
},
groups: {
default: () => [],
type: Array,
}
},
computed: {
cappedDescription () {
if (this.description && this.description.length > 100) {
return this.description.substring(0, 100) + '...';
} else {
return this.description;
}
}
}
};
</script>
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
"url-loader": "^0.6.2",
"viewport-units-buggyfill": "^0.6.2",
"visible": "^0.3.5",
"vue": "^2.5.13",
"waypoints": "^4.0.1",
"webpack-dev-server": "^2.11.1",
"webpack-manifest-plugin": "^1.3.2",
Expand Down Expand Up @@ -130,6 +131,8 @@
"testcafe": "^0.18.6",
"text-loader": "^0.0.1",
"transformer-proxy": "^0.3.4",
"vue-loader": "^14.1.1",
"vue-template-compiler": "^2.5.13",
"webpack": "^3.10.0",
"webpack-bundle-analyzer": "^2.9.2",
"webpack-config": "^7.5.0",
Expand Down
Loading