agola-web/src/components/projects.vue

72 lines
1.6 KiB
Vue
Raw Normal View History

2018-12-09 13:21:20 +00:00
<template>
<div>
<div class="item-list" v-for="project in projects" v-bind:key="project.id">
<router-link tag="div" class="item" :to="projectURL(project)">
<span class="name">{{project.name}}</span>
</router-link>
</div>
</div>
</template>
<script>
import { apiurl, fetch } from "@/util/auth";
export default {
components: {},
name: "Projects",
props: {
ownertype: String,
ownername: String
},
data() {
return {
projects: [],
polling: null
};
},
methods: {
projectURL(project) {
if (this.ownertype == "user") {
return {
name: "user project",
params: { username: this.ownername, projectname: project.name }
};
} else if (this.ownertype == "org") {
return {
name: "org project",
params: { orgname: this.ownername, projectname: project.name }
};
}
},
2019-03-29 17:19:07 +00:00
async fetchProjects(ownertype, ownername) {
2019-03-20 12:51:00 +00:00
let path =
"/projectgroups/" + encodeURIComponent(ownertype + "/" + ownername);
2018-12-09 13:21:20 +00:00
path += "/projects";
2019-03-29 17:19:07 +00:00
let res = await (await fetch(apiurl(path))).json();
console.log(res);
this.projects = res;
console.log("projects", this.projects);
2018-12-09 13:21:20 +00:00
}
},
created: function() {
this.fetchProjects(this.ownertype, this.ownername);
}
};
</script>
<style scoped lang="scss">
@import "@/css/_variables.scss";
.item-list {
.item {
margin-bottom: 5px;
border: 1px solid $grey-lighter;
cursor: pointer;
display: flex;
padding: 10px;
}
.name {
font-weight: bold;
}
}
</style>