forked from stevekrouse/WoofJS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.html
149 lines (135 loc) · 4.85 KB
/
user.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<link rel="shortcut icon" type="image/png" href="./favicon.png"/>
<style>
a {
font-size: 20px;
}
button {
min-height: 40px;
position: relative;
bottom: 6px;
}
button > input {
background-color: transparent;
border: 1px solid gray;
margin-left: 6px;
}
</style>
<script src="https://unpkg.com/[email protected]/dist/vue.js"></script>
<script src="https://www.gstatic.com/firebasejs/3.4.0/firebase.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<title>Projects</title>
<body>
<div id="page" class="container">
<h1 id="title">{{ name }}</h1>
<ul id="list" class="list-group">
<woof-project v-for="project in projects" :project="project"></woof-project>
</ul>
<div style="display:none" :style="{display: teamProjects.length ? 'block' : 'none'}">
<h1 id="title">Team Projects</h1>
<ul id="list" class="list-group">
<woof-team-project v-for="project in teamProjects" :project="project"></woof-team-project>
</ul>
</div>
</div>
<script id="project-template" type="text/x-template">
<a class="list-group-item list-group-item-action">{{ project.key }}
<span class="pull-right">
<button class="btn btn-info" @click="codeClick($event)" style="margin-right: 5px">View Version<input type="number" min="1" :max="project.revisions.length" :value="project.revisions.length" style="text-align: right; width: 3em"></input></button>
</span>
</a>
</script>
<script id="team-project-template" type="text/x-template">
<a class="list-group-item list-group-item-action">{{ project }}
<span class="pull-right">
<button class="btn btn-info" @click="codeClick($event)" style="margin-right: 5px">Open</button>
</span>
</a>
</script>
<script>
Vue.component('woof-project', {
template: "#project-template",
props: ["project"],
methods: {
codeClick: function($event) {
if ($event.target.nodeName == "BUTTON"){
window.open('./create.html#' + this.project.key + '/' + $event.target.firstElementChild.value, '_blank')
}
},
}
})
Vue.component('woof-team-project', {
template: "#team-project-template",
props: ["project"],
methods: {
codeClick: function($event) {
window.open('./team.html#' + this.project, '_blank')
},
}
})
var app = new Vue({
el: '#page',
data: {
name: "Loading...",
projects: [],
teamProjects: [],
}
})
var config = {
apiKey: "AIzaSyBYHv7dCiD0bWiHRlcp4VIZCIqzoMnB4yY",
authDomain: "woofjs-d1b27.firebaseapp.com",
databaseURL: "https://woofjs-d1b27.firebaseio.com",
storageBucket: "woofjs-d1b27.appspot.com",
messagingSenderId: "397293370524"
};
firebase.initializeApp(config);
var getUID = function() {
return window.location.hash.substring(1, window.location.hash.length);
}
firebase.database().ref('/user/' + getUID() + "/displayName").once('value', function(snap) {
if (snap.val()){
app.name = snap.val()
document.title = "Projects - " + snap.val()
}
});
firebase.database().ref('/user/' + getUID() + "/team").once('value', function(snap) {
if (snap.val()){
app.teamProjects = Object.values(snap.val())
}
});
var objectOfObjectsToArray = function(obj, keyName = "key"){
return Object.keys(obj).map(function(key) {
var child = obj[key]
child[keyName] = key
return child;
})
}
firebase.database().ref('/code/').orderByChild("--uid").equalTo(getUID()).once('value').then(function(snapshot) {
var projects = objectOfObjectsToArray(snapshot.val())
// nesting revisions under projects
app.projects = projects.map(function(project){
var keys = Object.keys(project)
var revisionKeys = keys.filter(key => key != '--uid' && key != 'key')
return {
key: project.key,
"--uid": project["--uid"],
revisions: revisionKeys.map(key => {
var revision = project[key]
revision.key = key
revision.project = project
return revision
})
}
})
})
</script>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-82374072-1', 'auto');
ga('send', 'pageview');
</script>
</body>