Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sulthon Abdul Malik #28

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
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
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"git.ignoreLimitWarning": true
}
2 changes: 2 additions & 0 deletions client-admin/.browserslistrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
> 1%
last 2 versions
17 changes: 17 additions & 0 deletions client-admin/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module.exports = {
root: true,
env: {
node: true
},
'extends': [
'plugin:vue/essential',
'eslint:recommended'
],
parserOptions: {
parser: 'babel-eslint'
},
rules: {
'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off'
}
}
21 changes: 21 additions & 0 deletions client-admin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
.DS_Store
node_modules
/dist

# local env files
.env.local
.env.*.local

# Log files
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Editor directories and files
.idea
.vscode
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
24 changes: 24 additions & 0 deletions client-admin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# vue-admin

## Project setup
```
yarn install
```

### Compiles and hot-reloads for development
```
yarn serve
```

### Compiles and minifies for production
```
yarn build
```

### Lints and fixes files
```
yarn lint
```

### Customize configuration
See [Configuration Reference](https://cli.vuejs.org/config/).
5 changes: 5 additions & 0 deletions client-admin/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
"presets": [
"@vue/cli-plugin-babel/preset"
]
}
39 changes: 39 additions & 0 deletions client-admin/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "client-admin",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint"
},
"dependencies": {
"axios": "^0.19.2",
"bootstrap-vue": "^2.1.0",
"core-js": "^3.6.4",
"sweetalert2": "^9.8.2",
"vue": "^2.6.11",
"vue-router": "^3.1.5",
"vuex": "^3.1.2"
},
"devDependencies": {
"@babel/polyfill": "^7.7.0",
"@vue/cli-plugin-babel": "^4.2.0",
"@vue/cli-plugin-eslint": "^4.2.0",
"@vue/cli-plugin-router": "^4.2.0",
"@vue/cli-plugin-vuex": "^4.2.0",
"@vue/cli-service": "^4.2.0",
"babel-eslint": "^10.0.3",
"bootstrap": "^4.3.1",
"eslint": "^6.7.2",
"eslint-plugin-vue": "^6.1.2",
"mutationobserver-shim": "^0.3.3",
"node-sass": "^4.12.0",
"popper.js": "^1.16.0",
"portal-vue": "^2.1.6",
"sass": "^1.19.0",
"sass-loader": "^8.0.2",
"vue-cli-plugin-bootstrap-vue": "^0.6.0",
"vue-template-compiler": "^2.6.11"
}
}
Binary file added client-admin/public/favicon.ico
Binary file not shown.
17 changes: 17 additions & 0 deletions client-admin/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
<title><%= htmlWebpackPlugin.options.title %></title>
</head>
<body>
<noscript>
<strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
</noscript>
<div id="app"></div>
<!-- built files will be auto injected -->
</body>
</html>
28 changes: 28 additions & 0 deletions client-admin/src/App.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<template>
<div id="app">
<router-view name="navbar" />
<router-view />
</div>
</template>

<script>
export default {
name: "App"
}
</script>

<style lang="scss">
html,
body {
height: 100%;
margin: 0;
padding: 0;
}

#app {
font-family: Avenir, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
color: #2c3e50;
}
</style>
Binary file added client-admin/src/assets/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions client-admin/src/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import '@babel/polyfill'
import 'mutationobserver-shim'
import Vue from 'vue'
import './plugins/bootstrap-vue'
import App from './App.vue'
import router from './router'
import store from './store'
import axios from 'axios'

axios.defaults.baseURL = "http://localhost:3000"

Vue.config.productionTip = false;

Vue.use(axios)

new Vue({
router,
store,
render: h => h(App)
}).$mount('#app')
7 changes: 7 additions & 0 deletions client-admin/src/plugins/bootstrap-vue.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Vue from 'vue'

import BootstrapVue from 'bootstrap-vue'
import 'bootstrap/dist/css/bootstrap.min.css'
import 'bootstrap-vue/dist/bootstrap-vue.css'

Vue.use(BootstrapVue)
115 changes: 115 additions & 0 deletions client-admin/src/router/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import Vue from "vue";
import VueRouter from "vue-router";
import store from '../store';
import Navbar from "../views/components/Navbar.vue";
import Home from "../views/Home.vue";

Vue.use(VueRouter);

const routes = [
{
path: "/",
name: "Home",
components: {
default: Home,
navbar: Navbar
},
beforeEnter(to, from, next) {
if (!store.state.isLogin || store.state.user.role !== "admin") {
store.dispatch("logout");
}
else {
next();
}
}
},
{
path: "/product-detail",
name: "ProductDetail",
components: {
default: () => import(/* webpackChunkName: "about" */ '../views/ProductDetail'),
navbar: Navbar
},
beforeEnter(to, from, next) {
if (!store.state.isLogin || store.state.user.role !== "admin") {
store.dispatch("logout");
}
else {
next();
}
},
children: [
{
path: "",
redirect: "/"
},
{
path: ":id",
name: "ProductDetailId",
component: () => import(/* webpackChunkName: "about" */ '../views/ProductDetail/ProductById.vue')
}
]
},
{
path: "/product-add",
name: "ProductAdd",
components: {
default: () => import(/* webpackChunkName: "about" */ '../views/ProductAdd.vue'),
navbar: Navbar
}
},
{
path: "/about",
name: "About",
// route level code-splitting
// this generates a separate chunk (about.[hash].js) for this route
// which is lazy-loaded when the route is visited.
// components: {
// default: () => import(/* webpackChunkName: "about" */ '../views/About.vue'),
// navbar: () =>
// }
components: {
default: () => import(/* webpackChunkName: "about" */ '../views/About.vue'),
navbar: Navbar
}
},
{
path: "/dashboard",
name: "Dashboard",
components: {
default: () => import(/* webpackChunkName: "about" */ '../views/Dashboard.vue'),
navbar: Navbar
}
},
{
path: "/login",
name: "Login",
components: {
default: () => import(/* webpackChunkName: "about" */ '../views/Login.vue'),
navbar: ""
}
},
{
path: "/register",
name: "Register",
components: {
default: () => import(/* webpackChunkName: "about" */ '../views/Register.vue'),
navbar: ""
}
}
];

const router = new VueRouter({
mode: "history",
base: process.env.BASE_URL,
routes
});

router.beforeEach((to, from, next) => {
if(!store.state.isLogin) {
store.dispatch("autoLogin");
}
next();
})

export default router;
87 changes: 87 additions & 0 deletions client-admin/src/store/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import Vue from 'vue'
import Vuex from 'vuex'
import axios from 'axios';
import Swal from 'sweetalert2';
import router from '../router';
// import router from '../router';
// import user from './modules/user';

Vue.use(Vuex)

export default new Vuex.Store({
state: {
isLogin: false,
user: {}
},
mutations: {
},
actions: {
registerAdmin(context, payload) {
axios({
url: "/users/register",
method: "post",
data: {
name: payload.name.trim(),
email: payload.email.trim(),
password: payload.password,
role: "admin"
}
})
.then(() => {
router.push("/login");
}).catch((err) => {
console.error(err);
Swal.fire({
title: "Something went wrong",
icon: "error"
})
});
},
login(context, payload) {
Swal.showLoading();
axios({
url: "/users/login",
method: "post",
data: {
email: payload.email,
password: payload.password,
}
})
.then(({ data }) => {
for (const key in data) {
let value = data[key];
if (typeof value === "object") {
value = JSON.stringify(value);
}
localStorage.setItem(key, value);
}
Swal.close();
router.push("/");
}).catch((err) => {
Swal.fire({
title: "Email or Password is Wrong",
icon: "error"
})
console.error(err);
});
},
autoLogin({ state }) {
if (!localStorage.getItem("access_token")) {
return;
}
else {
const user = JSON.parse(localStorage.getItem("user"));
state.isLogin = true;
state.user = user;
}
},
logout({ state }) {
localStorage.clear();
state.isLogin = false;
state.user = {};
router.push("/login");
}
},
modules: {
}
})
Loading