Skip to content

Commit

Permalink
Merge pull request #4 from zarathustra323/primary-section
Browse files Browse the repository at this point in the history
Convert lib to use queue function; create primary section component
  • Loading branch information
zarathustra323 authored Oct 17, 2019
2 parents 5a2fa25 + 0729d68 commit 839bed1
Show file tree
Hide file tree
Showing 45 changed files with 522 additions and 283 deletions.
36 changes: 26 additions & 10 deletions demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,45 @@
<head>
<meta charset="utf-8">
<title>bmc demo</title>
<script src="./dist/0.4.0/bmc.umd.min.js"></script>
<script async src="./dist/0.4.0/bmc.umd.min.js"></script>
<script>
bmc.configure({
graphqlUri: 'http://0.0.0.0:11001',
(function(w, f) {
var l = f + 'Queue'; w[l] = w[l] || [];
w[f] = w[f] || function() { w[l].push(arguments); };
})(window, 'bmc');
</script>
<link rel="stylesheet" href="./dist/0.4.0/bmc.css">
</head>
<body>
<script>
bmc('configure', {
graphqlUri: 'https://caprica.graphql-staging.base-cms.io',
tenantKey: 'acbm_fcp',
baseApiUri: 'https://manage.forconstructionpros.com',
debug: true,
});
</script>
<link rel="stylesheet" href="./dist/0.4.0/bmc.css">
</head>
<body>

<div id="bmc-datetime-portal" class="bmc-portal"></div>
<h1>Scheduling</h1>
<div id="scheduling"></div>
<div id="component-scheduling"></div>

<h1>Primary Section</h1>
<div id="component-primary-section"></div>

<script>
bmc.loadComponent({
bmc('loadComponent', {
name: 'scheduling',
el: '#scheduling',
el: '#component-scheduling',
props: { contentId: 21091788 },
on: { mount: () => console.log('received mount') }
});
bmc('loadComponent', {
name: 'primary-section',
el: '#component-primary-section',
props: { sectionId: 54320 },
on: { change: (section) => console.log('primary-section change', section) }
});
</script>

</body>
</html>
74 changes: 64 additions & 10 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
<title>BaseCMS Management Components</title>
<script>
(function(w, f) {
var l = f + 'Queue'; w[l] = w[l] || [];
w[f] = w[f] || function() { w[l].push(arguments); };
})(window, 'bmc');
</script>

<style>
/* example styles */
*,
Expand All @@ -14,42 +21,89 @@
box-sizing: border-box;
}
html {
font-family: sans-serif;
font-family: serif;
line-height: 1.15;
}
body {
margin: 0;
text-align: left;
}
.example-container {
.container {
width: 100%;
padding-right: 15px;
padding-left: 15px;
margin-right: auto;
margin-left: auto;
}
.example-row {
.row {
display: flex;
flex-wrap: wrap;
margin-right: -15px;
margin-left: -15px;
}
.example-col {
flex-basis: 0;
flex-grow: 1;
max-width: 100%;
.col {
flex: 0 0 100%;
width: 100%;
padding-right: 15px;
padding-left: 15px;
}
</style>
</head>
<body>
<script>
bmc('configure', {
graphqlUri: 'https://caprica.graphql-staging.base-cms.io',
tenantKey: 'acbm_fcp',
baseApiUri: 'https://manage.forconstructionpros.com',
debug: true,
});

bmc('loadComponent', {
name: 'scheduling',
el: '#component-scheduling',
props: { contentId: 21091788 },
});

bmc('loadComponent', {
name: 'primary-section',
el: '#component-primary-section-empty',
on: { change: (section) => console.log('primary-section change', section) }
});

bmc('loadComponent', {
name: 'primary-section',
el: '#component-primary-section-preselected',
props: { sectionId: 54320 },
on: { change: (section) => console.log('primary-section change', section) }
});


</script>
<div id="bmc-datetime-portal" class="bmc-portal"></div>
<noscript>
<strong>We're sorry but this page doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
</noscript>
<div class="example-container">
<div class="example-row">
<div id="app"></div>
<div class="container">
<div class="row">
<div class="col" style="max-width: 380px;">
<h4>Scheduling</h4>
<div id="component-scheduling"></div>
</div>
</div>

<div class="row">
<div class="col" style="max-width: 500px;">
<h4>Primary Section (Empty)</h4>
<div id="component-primary-section-empty"></div>
</div>
</div>

<div class="row">
<div class="col" style="max-width: 500px;">
<h4>Primary Section (Pre-Selected)</h4>
<div id="component-primary-section-preselected"></div>
</div>
</div>
</div>
</body>
</html>
3 changes: 2 additions & 1 deletion scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ vue-cli-service build \
--no-clean \
--target lib \
--inline-vue \
--name bmc \
--name BMCObject \
--filename bmc \
--dest dist/$1 \
--formats umd-min \
src/lib.js
76 changes: 0 additions & 76 deletions src/App.vue

This file was deleted.

4 changes: 3 additions & 1 deletion src/apollo/create-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import { ApolloClient } from 'apollo-client';
import { createHttpLink } from 'apollo-link-http';
import { InMemoryCache } from 'apollo-cache-inmemory';
import fragmentMatcher from './fragment-matcher';
import { name, version } from '../../package.json';

export default ({ uri, headers }) => new ApolloClient({
name: 'Management Components',
name,
version,
link: createHttpLink({ uri, headers }),
cache: new InMemoryCache({ fragmentMatcher }),
});
119 changes: 119 additions & 0 deletions src/components/common/fields/website/section.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
<template>
<tree-select
v-model="currentSection"
value-format="object"
:auto-load-root-options="false"
:backspace-removes="false"
:clearable="clearable"
:default-expand-level="defaultExpandLevel"
:disabled="disabled"
:flat="true"
:load-options="loadChoices"
:multiple="false"
:options="choices"
:placeholder="placeholder"
:required="required"
:show-count="showCount"
@open="$emit('open')"
@close="$emit('close')"
@input="emitChange"
search-nested
>
<div slot="value-label" slot-scope="{ node }">{{ node.raw.title }}</div>
<label
slot="option-label"
slot-scope="{ node, shouldShowCount, count, labelClassName, countClassName }"
:class="labelClassName"
@click="toggleExpanded(node)"
>
{{ node.label }}
<span v-if="shouldShowCount" :class="countClassName">({{ count }})</span>
</label>
</tree-select>
</template>

<script>
import TreeSelect, { LOAD_ROOT_OPTIONS } from '@riophae/vue-treeselect';
import loadChoices from '../../../utils/website-section/load-site-choices';
import createSectionNode from '../../../utils/website-section/create-node';
export default {
props: {
section: {
type: Object,
default: null,
},
placeholder: {
type: String,
default: 'Select section; type to filter...',
},
disabled: {
type: Boolean,
default: false,
},
clearable: {
type: Boolean,
default: false,
},
showCount: {
type: Boolean,
default: true,
},
required: {
type: Boolean,
default: true,
},
nodeOptions: {
type: Object,
default: () => ({}),
},
},
data: () => ({
choices: null,
}),
components: {
TreeSelect,
},
computed: {
currentSection: {
get() {
return createSectionNode(this.section, this.nodeOptions);
},
set() {
},
},
defaultExpandLevel() {
return this.choices && this.choices.length === 1 ? 1 : 0;
},
},
methods: {
emitChange(choice) {
const section = choice ? choice.model : null;
this.$emit('change', section);
},
toggleExpanded(node) {
const { isSite } = (node || {}).raw;
// eslint-disable-next-line no-param-reassign
if (isSite) node.isExpanded = !node.isExpanded;
},
async loadChoices({ action }) {
if (action === LOAD_ROOT_OPTIONS) {
const { section } = this;
const expandedIds = [];
if (section) {
if (section.site) expandedIds.push(section.site.id);
if (section.hierarchy) expandedIds.push(...section.hierarchy.map(s => s.id));
}
this.choices = await loadChoices(this.$apollo, { ...this.nodeOptions, expandedIds });
}
},
},
};
</script>
Loading

0 comments on commit 839bed1

Please sign in to comment.