Skip to content

Commit

Permalink
hardcoded bits
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Ban committed Sep 27, 2019
0 parents commit 20827f9
Show file tree
Hide file tree
Showing 12 changed files with 880 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
traefiker
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.PHONY: install linux
all:
go build .

linux:
GOOS=linux go build . && goupx traefiker

install: linux
scp traefiker blinker:blinker/
8 changes: 8 additions & 0 deletions blinker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM scratch
ADD blinker /
ADD config.yml /
ADD index.html /
ADD load.html /
ADD auth.html /
EXPOSE 80/tcp
CMD ["/blinker","serve"]
39 changes: 39 additions & 0 deletions blinker/auth.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<!DOCTYPE html>
<html>
<header>
<script src="//cdn.bigcommerce.com/jssdk/bc-sdk.js"></script>
<link rel="stylesheet" type="text/css" href="//unpkg.com/bootstrap/dist/css/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="//unpkg.com/bootstrap-vue@latest/dist/bootstrap-vue.css"/>
<script>
Bigcommerce.init({
onLogout: function() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
console.log(this.responseText);
}
};
xhttp.open("GET", "/logout", true);
xhttp.send();
}
});
</script>
<style>
nav {
background-color: #1d3650;
margin: 0 0 10px 0;
padding: 5px;
color: white;
}
</style>
</header>
<body>
<nav>
<h2>Welcome!</h2>
</nav>
<p>Please reload the page if it doesn't reload.</p>
<script>
window.opener.location.reload(false);
</script>
</body>
</html>
28 changes: 28 additions & 0 deletions blinker/blinker
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<html>
<head>
<style>
nav {
background-color: #1d3650;
margin: 0;
padding: 5px;
}
body {
margin: 0;
font-family: "CircularStd","Helvetica Neue",Helvetica,Arial,sans-serif;
}
.container {
margin: 10px;
}
</style>
</head>
<body>
<nav>
<img src="/static/gpmd-logo--light.svg" alt="GPMD" />
</nav>
<div class="container">
<h1>Welcome!</h1>
Please see our BigCommerce deals at
<a href="https://www.gpmd.co.uk/bigcommerce">gpmd.co.uk/bigcommerce</a>
</div>
</body>
</html>
17 changes: 17 additions & 0 deletions blinker/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
balanceme:
db: root:myohmy69@(mysql:3306)/blinker?parseTime=true
client: 27t27zo6uxju556q6biq9a6129dryjg
token: 1u4bq84z36psc8q6npidp8gt7vc2m5k
store: o1p74e2tyg
redis: redis:6379
hostname: blinker.gpmd.net
ssl: false
auth:
auth_url: https://login.bigcommerce.com/oauth2/authorize
token_url: https://login.bigcommerce.com/oauth2/token

scopes: # https://developer.bigcommerce.com/api-docs/getting-started/authentication#authentication_oauth-scopes
- store_v2_content_read_only
- store_v2_default
- store_v2_products_read_only
- users_basic_information
28 changes: 28 additions & 0 deletions blinker/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<html>
<head>
<style>
nav {
background-color: #1d3650;
margin: 0;
padding: 5px;
}
body {
margin: 0;
font-family: "CircularStd","Helvetica Neue",Helvetica,Arial,sans-serif;
}
.container {
margin: 10px;
}
</style>
</head>
<body>
<nav>
<img src="/static/gpmd-logo--light.svg" alt="GPMD" />
</nav>
<div class="container">
<h1>Welcome!</h1>
Please see our BigCommerce deals at
<a href="https://www.gpmd.co.uk/bigcommerce">gpmd.co.uk/bigcommerce</a>
</div>
</body>
</html>
203 changes: 203 additions & 0 deletions blinker/load.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
<!DOCTYPE html>
<html>
<header>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.min.js"></script>
<script src="//unpkg.com/babel-polyfill@latest/dist/polyfill.min.js"></script>
<script src="//unpkg.com/bootstrap-vue@latest/dist/bootstrap-vue.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
<link rel="stylesheet" type="text/css" href="//unpkg.com/bootstrap/dist/css/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="//unpkg.com/bootstrap-vue@latest/dist/bootstrap-vue.css"/>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"/>
<script src="https://unpkg.com/[email protected]"></script>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/vue-multiselect.min.css">
<script src="//cdn.bigcommerce.com/jssdk/bc-sdk.js"></script>
<script>
Bigcommerce.init({
onLogout: function() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
console.log(this.responseText);
}
};
xhttp.open("GET", "/logout", true);
xhttp.send();
}
});
</script>
<style>
#table {
margin: 0 auto;
width: 90%;

.input-group-text {
padding: 0 .5em 0 .5em;

.fa {
font-size: 12px;
}
}
}
nav {
background-color: #1d3650;
margin: 0 0 10px 0;
padding: 5px;
color: white;
}
</style>
</header>
<body>
<div id="table">
<nav>
<h2>Blog Articles</h2>
</nav>
<b-button class="float-right mb-3" @click="syncCall()">Sync</b-button>
<b-input-group>
<b-form-input v-model="keyword" placeholder="Search" type="text"></b-form-input>
<b-input-group-text slot="append">
<b-btn class="p-0" :disabled="!keyword" variant="link" size="sm" @click="keyword = ''"><i class="fa fa-remove"></i></b-btn>
</b-input-group-text>
</b-input-group>
<b-table :fields="fields" :items="items" :keyword="keyword" sort-by="ext_id" sort-desc=true outlined>
<template slot="title" slot-scope="row">
<a :href="'{{.ac.URL}}'+row.item.url.substr(1)" target="_new">{{"{{row.item.title}}"}}</a>
</template>
<template slot="actions" slot-scope="row">
<b-button :href="{{"'"}}{{.ac.URL}}{{"manage/content/blog/post/'+row.item.ext_id"}}">Edit Post</b-button>
</template>
<template slot="featured" slot-scope="row">
<input type="checkbox" id="checkbox" :id="'checkbox'+row.index" @input="s => onChangeFeatured(row.item)" v-model="row.item.featured">
</template>
<template slot="assigned" slot-scope="row">
<b-modal :id="'modal-'+row.item.ext_id" title="Edit" hide-footer>
Products:
<multiselect v-model="row.item.assigned" placeholder="Assign products" :custom-label="customLabel" label="name" track-by="ext_id" @input="onChange(row.item.ext_id,...arguments)" :options="options" :multiple="true" :taggable="true"></multiselect>
Categories:
<multiselect v-model="row.item.assignedcats" placeholder="Assign categories" :custom-label="customLabel" label="name" track-by="ext_id" @input="onChangeCats(row.item.ext_id,...arguments)" :options="catoptions" :multiple="true" :taggable="true"></multiselect>
Brands:
<multiselect v-model="row.item.assignedbrands" placeholder="Assign brands" :custom-label="customLabel" label="name" track-by="ext_id" @input="onChangeBrands(row.item.ext_id,...arguments)" :options="brandoptions" :multiple="true" :taggable="true"></multiselect>
</b-modal>
<div v-if="row.item.assigned.length > 0" @click="$bvModal.show('modal-'+row.item.ext_id)">{{"<span class=\"multiselect__tag\" v-for=\"i in row.item.assigned\">{{i.name}}</span>"}}</div>
<b-button v-else v-b-modal="'modal-'+row.item.ext_id">Assign Products</b-button>
<div v-if="row.item.assignedcats.length > 0" @click="$bvModal.show('modal-'+row.item.ext_id)">{{"<span class=\"multiselect__tag orange\" v-for=\"i in row.item.assignedcats\">{{i.name}}</span>"}}</div>
<b-button v-else v-b-modal="'modal-'+row.item.ext_id">Assign Categories</b-button>
<div v-if="row.item.assignedbrands.length > 0" @click="$bvModal.show('modal-'+row.item.ext_id)">{{"<span class=\"multiselect__tag blue\" v-for=\"i in row.item.assignedbrands\">{{i.name}}</span>"}}</div>
<b-button v-else v-b-modal="'modal-'+row.item.ext_id">Assign Brands</b-button>
</template>
</b-table>
</div>
<script>
Vue.component('multiselect', window.VueMultiselect.default)
new Vue({
el: '#table',
data () {
return {
keyword: '',
options: [
{{range $i, $v := .products}}{ name: '{{ replace $v.Name "'" "\\'"}}', ext_id: {{$v.ExtID}}, sku: '{{ $v.SKU }}' },{{end}}
],
catoptions: [
{{range $i, $v := .categories}}{ name: '{{ replace $v.FullName "'" "\\'"}}', ext_id: {{$v.ExtID}} },{{end}}
],
brandoptions: [
{{range $i, $v := .brands}}{ name: '{{ replace $v.Name "'" "\\'"}}', ext_id: {{$v.ExtID}} },{{end}}
],
dataArray: [
{{range $i, $v := .blog}}{ title: '{{ replace $v.Title "'" "\\'"}}', ext_id: {{$v.ExtID}}, featured: {{$v.Featured}},
assigned: [
{{range $j, $a := $v.Assigned}}
{{if $j}},
{{end}}
{ name: '{{ replace $a.Name "'" "\\'"}}', ext_id: '{{$a.ExtID}}', sku: '{{ $a.SKU }}' }
{{end}}
],
assignedcats: [
{{range $j, $a := $v.AssignedCats}}
{{if $j}},
{{end}}
{ name: '{{ replace $a.FullName "'" "\\'"}}', ext_id: '{{$a.ExtID}}' }
{{end}}
],
assignedbrands: [
{{range $j, $a := $v.AssignedBrands}}
{{if $j}},
{{end}}
{ name: '{{ replace $a.Name "'" "\\'"}}', ext_id: '{{$a.ExtID}}' }
{{end}}
],
url: '{{ $v.URL }}' },{{end}}
],
fields: [
{key: 'ext_id', label: 'ID', sortable: true},
{key: 'actions', label: '', sortable: false},
{key: 'title', label: 'Title', sortable: true},
{key: 'featured', label: 'Featured', sortable: true},
{key: 'assigned', label: 'Connections', sortable: false, thStyle: "width:30%;", tdStyle: "width:30%;" },
]
}
/* {{.blog}} */
},
methods: {
sendCommand(extid, mode, newvals) {
console.log("new:",extid, newvals);
var assigned = [];
newvals.forEach(element => {
assigned.push(parseInt(element.ext_id));
});
console.log("assigned:",assigned);
this.$http.post('/savepost',{"mode":mode, "extid": extid, "assigned": assigned}).then(response => {
console.log(response);
}, response => {
console.log(response);
})
},
onChange (extid, newvals) {
this.sendCommand(extid, "products", newvals);
},
onChangeCats (extid, newvals) {
this.sendCommand(extid, "cats", newvals);
},
onChangeBrands (extid, newvals) {
this.sendCommand(extid, "brands", newvals);
},
onChangeFeatured (item, newvals, e) {
console.log("feat:",item.ext_id, !item.featured);
this.$http.post('/savepost',{"mode":"featured", "extid": item.ext_id, "featured": !item.featured}).then(response => {
console.log(response);
}, response => {
console.log(response);
})
},
customLabel({ name, ext_id, sku }) {
return name;
},
syncCall() {
this.$http.get('/sync').then(response => {
alert("Sync started");
console.log(response);
}, response => {
alert("Sync problem");
console.log(response);
})
}
},
computed: {
items () {
return this.keyword
? this.dataArray.filter(item => item.title.toLowerCase().includes(this.keyword.toLowerCase()))
: this.dataArray
}
}
})
</script>
</body>
</html>

<style>
.orange {
background-color: rgb(177, 97, 0);
}
.blue {
background-color: rgb(3, 0, 177);
}
</style>
11 changes: 11 additions & 0 deletions config.yml.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
traefiker:
name: blinker # Docker container name
docker:
links: ["traefik_mysql_1:mysql", "traefik_redis_1:redis"] # Linked containers, "docker_name:internal_name" format
networks: ["traefik_web"]
labels:
traefik.backend: blinker # Same as traefiker.name above
traefik.docker.network: traefik_web # Same as traefiker.network above
traefik.frontend.rule: Host: linker.gpmd.net
traefik.frontend.entryPoints: https
traefik.port: 80 # exposed port from Docker image
14 changes: 14 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module github.com/gpmd/traefiker

go 1.13

require (
github.com/docker/distribution v2.7.1+incompatible // indirect
github.com/docker/docker v1.13.1
github.com/docker/go-connections v0.4.0
github.com/docker/go-units v0.4.0 // indirect
github.com/opencontainers/go-digest v1.0.0-rc1 // indirect
github.com/pkg/errors v0.8.1 // indirect
github.com/spf13/viper v1.4.0
golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297 // indirect
)
Loading

0 comments on commit 20827f9

Please sign in to comment.