Skip to content
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
Binary file added .DS_Store
Binary file not shown.
1 change: 0 additions & 1 deletion README.md

This file was deleted.

Binary file added client/.DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions client/assets/404.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions client/assets/register.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions client/assets/security.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
63 changes: 63 additions & 0 deletions client/components/addArticle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// const serverUrl = `http://localhost:3000`

Vue.component('add-article',{
template : `
<div class="card" >

<div class="card-header" >
Add Article
</div>
<div class="card-body">
<form method="POST" v-on:submit.prevent="addArticle" enctype="multipart/form-data">
<div class="form-group">
<label>Article Title</label>
<input type="text" class="form-control" v-model="title" id="name"
placeholder="Enter Article Name/Title">
</div>
<div class="form-group">
<label>Image</label>
<input type="file" class="form-control" @change="uploadImage">
</div>
<div class="form-group">
<label>Content</label>
<wysiwyg v-model="content" />
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
</div>
</div>
`,
data : function(){
return {
title : '',
content : '',
image : ''
}
},
components: {
wysiwyg: vueWysiwyg.default.component,
},
methods : {
uploadImage: function(e){
this.image = e.target.files[0]
},
addArticle: function () {
let formData = new FormData
formData.append('image',this.image)
formData.append('title', this.title)
formData.append('content', this.content)
axios
.post(`${serverUrl}/articles`, formData)
.then(({data}) => {
this.title = ''
this.content = ''
this.$emit('add-new',data)
// return this.getAllArticle()
})
.catch(error => {
console.log(error);
// this.errorMsg = error.response.data.message
})
}
}
})
60 changes: 60 additions & 0 deletions client/components/editForm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
Vue.component('edit-form', {
template: `
<div class="card" >

<div class="card-header" >
Add Article
</div>
<div class="card-body">
<form method="POST" v-on:submit.prevent="submitEditArticle(dataFill.id)" enctype="multipart/form-data">
<div class="form-group">
<label>Article Title</label>
<input type="text" class="form-control" v-model="title" id="name"
value="dataFill.title">
</div>
<div class="form-group">
<label>Image</label>
<input type="file" class="form-control" @change="uploadImage">
</div>
<div class="form-group">
<label>Content</label>
<wysiwyg v-model="content" value="dataFile.content" />
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
</div>
</div>
`,
props: ['dataFill'],
data: function () {
return {
title: '',
content: '',
image: ''
}
},
components: {
wysiwyg: vueWysiwyg.default.component,
},
methods: {
uploadImage: function (e) {
this.image = e.target.files[0]
},
submitEditArticle: function (id) {
let formData = new FormData
formData.append('image', this.image)
formData.append('title', this.title)
formData.append('content', this.content)
axios
.put(`${serverUrl}/articles/${id}`, formData)
.then(response => {

this.$emit('editstatus', 'editdone')

})
.catch(err => {
console.log(err)
})
}
}
})
61 changes: 61 additions & 0 deletions client/components/listArticle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
Vue.component('list-article', {
template : `
<div class="">
<div id="content" class="container overflow-auto pb-3" v-for="(article, index) in filtered">
<div class="card">
<div class="card-header">
#{{index+1}} {{ article.title }}
</div>
<div class="card-body">
<div class="row">
<div class="d-flex col-sm-2">
<img :src="article.image" alt="img" style="width:100%; height: 100px"
class="img-thumbnail">
</div>
<div class="d-flex flex-column col-sm-10">
<h5 class="card-title">{{ article.title }}</h5>
<p class="card-text" v-html="article.content"></p>
<p class="card-text">{{ formatedDate(article.createdAt) }}</p>
</div>
</div>
</div>
<div class="card-footer">
<a href="#" class="btn btn-warning" @click="startEditArticle(article._id)">Edit Article</a>
<a href="#" v-if="edstatus === 'editNow'" class="btn btn-info" @click="edstatus = 'editStop'">Cancel Edit</a>
<a href="#" class="btn btn-danger" @click="deleteArticle(article._id)">Delete Article</a>
<edit-form v-if="edstatus === 'editNow'" @editstatus="editStatus" :dataFill="editFill"></edit-form>
</div>
</div>
</div>
</div>
`,
props : ['filtered','searchWord'],
data : function (){
return {
editFill : {},
edstatus : ''
}
},
methods : {
editStatus : function(value){
if (value === "editdone") this.statusEdit = ''
},
formatedDate: function (tanggal) {
return moment(tanggal).format('MMMM Do YYYY, h:mm:ss a')
},
startEditArticle: function(id) {
axios
.get(`${serverUrl}/articles/${id}`)
.then(response => {
this.editFill.title = response.data.title
this.editFill.content = response.data.content
this.editFill.id = response.data._id
console.log(this.editFill)
this.edstatus = 'editNow'
})
.catch(error => {
console.log(error.response.data.message)
})
}
}
})
66 changes: 66 additions & 0 deletions client/components/loginForm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
Vue.component('login-form',{
methods : {
loginPage: function () {
axios
.post(`http://localhost:3000/users/login`, {
email: this.email,
password: this.password
})
.then(({data}) => {
swal("Login berhasil, selamat datang",{
button : false,
timer : 1500,
icon : 'success'
})
localStorage.setItem('token', data.access_token)
localStorage.setItem('id', data.id)
this.$emit('login', 'login')
this.$emit('login-status', true)
})
.catch(err => {
this.errorMsg = err.response.data.msg
})
},

},
data : function(){
return {
errorMsg : '',
email : '',
password : ''
}
},
template : `
<div class="container my-1 overflow-auto ">
<div v-on:click="errorMsg = '' " v-if="errorMsg">
<h4 class="text-center">error message :</h4>
<h4 class="text-center text-danger">{{errorMsg}}</h4>
</div>
<div class="row">
<div class="col-12 p-0 d-flex flex-column">
<img src="/assets/security.svg" alt="" style="height:35%;" class="text-center mx-auto" />
<h5 class="font-weight-light mb-3 text-center">You shall not pass, please verify your identity</h5>
<div class="row">
<div class="col-md-6 mx-auto">
<form method="POST" v-on:submit.prevent="loginPage">
<div class="form-group">
<label for="emailInput">Email address</label>
<input type="email" class="form-control" id="emailInput" v-model="email" aria-describedby="emailHelp"
placeholder="Enter email" />
</div>

<div class="form-group">
<label for="passwordInput">Password</label>
<input type="password" class="form-control" id="passwordInput" v-model="password" aria-describedby="emailHelp"
placeholder="Enter password" />
</div>

<button type="submit" class="btn btn-primary btn-block">Log In</button>
</form>
</div>
</div>
</div>
</div>
</div>
`
})
118 changes: 118 additions & 0 deletions client/components/mainContent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
Vue.component('main-content',{
template : `
<div class="col-sm-10 overflow-auto" style="height:450px">

<div class="card" style="width:200px" v-if="currentContent === 'search' ">
<a href="#" class="btn btn-danger" @click="currentContent = '' ">Clear Search Results</a>
</div>
<br>
<div id="search-content" class="container overflow-auto pb-3"
v-if="currentContent === 'search'"
v-for="(search, index) in searchResult">
<div class="card">
<div class="card-header">
#{{index+1}} {{ search.title }}
</div>
<div class="card-body">
<h5 class="card-title">{{ search.title }}</h5>
<p class="card-text">{{ search.content }}</p>
<p class="card-text">{{ search.created_at }}</p>
<a href="#" class="btn btn-warning">Baca lebih detail</a>
</div>
</div>
</div>

<div v-if="currentContent==='no articles found'">
<img src="/assets/404.svg" alt="" style="height:200px;" class="d-flex justify-content-center text-center mx-auto" />
<h5 class="font-weight-light mb-3 text-center">No articles found</h5>
</div>

<div class="card" v-if="currentContent === 'addArticle'" >

<div class="card-header" >
Add Article
</div>
<div class="card-body">
<form method="POST" v-on:submit.prevent="addArticle" enctype="multipart/form-data">
<div class="form-group">
<label>Article Title</label>
<input type="text" class="form-control" v-model="title" id="name"
placeholder="Enter Article Name/Title">
<small id="emailHelp" class="form-text text-muted">make it descriptive.</small>
</div>
<div class="form-group">
<label>Image</label>
<input type="file" class="form-control" @change="uploadImage">
</div>
<div class="form-group">
<label>Content</label>
<!-- <textarea class="form-control" v-model="content" id="description" rows="2"></textarea> -->
<wysiwyg v-model="content" />
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>

</div>
</div>

<div class="container d-flex justify-content-center ">
<div class="searchbar" v-if="currentContent === 'listAll' " >
<input class="search_input" type="text" v-model="searchWord" placeholder="Search...">
<a href="#" class="search_icon"><i class="fas fa-search"></i></a>
</div>
</div>
<br>

<div id="content" class="container overflow-auto pb-3" v-if="currentContent === 'listAll' "
v-for="(article, index) in filtered">
<div class="card">
<div class="card-header">
#{{index+1}} {{ article.title }}
</div>
<div class="card-body">
<div class="row">
<div class="d-flex col-sm-2">
<img :src="article.image" alt="img" style="width:100%; height: 100px"
class="img-thumbnail">
</div>
<div class="d-flex flex-column col-sm-10">
<h5 class="card-title">{{ article.title }}</h5>
<p class="card-text" v-html="article.content"></p>
<p class="card-text">{{ formatedDate(article.createdAt) }}</p>
</div>
</div>
<br>
<div>
<a href="#" class="btn btn-warning"
v-on:click="startEditArticle(index,article._id)">Edit Article</a>
<a href="#" class="btn btn-danger" v-on:click="deleteArticle(article._id)">Delete
Article</a>
<div v-if="form === index ">
<form method="POST" v-on:submit.prevent="submitEditArticle(article._id)">
<div class="form-group">
<label>Article Title</label>
<input type="text" class="form-control" v-model="title" id="name">
<small id="emailHelp" class="form-text text-muted">make it
descriptive.</small>
</div>
<div class="form-group">
<label>Content</label>
<!-- <textarea class="form-control" v-model="content" id="description" rows="2"></textarea> -->
<wysiwyg v-model="content" value="article.content" />
</div>
<button type="submit" class="btn btn-primary">Submit</button>
<a href="#" class="btn btn-warning"
v-on:click="form = ''">Cancel Edit</a>
</form>
</div>
<div v-else></div>
</div>



</div>
</div>
</div>
</div>
`
})
Loading