Merge branch 'too/notificationpagination' into 'master'

Too/notificationpagination

See merge request CIEFWorldwideSdnBhd/exchange!86
This commit is contained in:
Jack Goh
2018-07-27 02:02:00 +00:00
6 changed files with 82 additions and 36 deletions
+2 -1
View File
@@ -359,8 +359,9 @@ class BookingController extends Controller
// $booking->usd_book_cnap = $request->input('usd_book_cnap');
// $booking->usd_book_bank_branch = $request->input('usd_book_bank_branch');
// $booking->verification_status = $request->input('verification_status');
// return response()->json($booking, 201);
$booking->save();
//return response()->json('error', 400);
// return response()->json('error', 400);
return response()->json($booking, 201);
}
@@ -42,15 +42,16 @@ class NotificationController extends Controller
public function getUserMessage()
{
$user_all_notification = Notification::Where("user_id",Auth::user()->id)->orderby('updated_at','desc')->get();
$user_all_notification = Notification::Where("user_id",Auth::user()->id)
->orderby('updated_at','desc')
->paginate(5);
$user_unread_notification = Notification::Where([["user_id",Auth::user()->id],["is_read",0]])
->orderby('updated_at','desc')
->get();
return response()->json([
"message" =>$user_all_notification,
"unread_message" =>Notification::Where([
["user_id",Auth::user()->id],
["is_read",0]
])->orderby('updated_at','desc')->get()
"unread_message" =>$user_unread_notification
],200);
}
+3 -3
View File
@@ -1,7 +1,7 @@
{
"/js/lang-zh-CN.489521629fd49ac7628e.js": "/js/lang-zh-CN.489521629fd49ac7628e.js",
"/js/lang-es.459dcb868aa54d488979.js": "/js/lang-es.459dcb868aa54d488979.js",
"/js/lang-en.31386792460363b93c17.js": "/js/lang-en.31386792460363b93c17.js",
"/js/lang-zh-CN.c0da3973e52421a8cfe5.js": "/js/lang-zh-CN.c0da3973e52421a8cfe5.js",
"/js/lang-es.f4a1a5b4a30e92527b46.js": "/js/lang-es.f4a1a5b4a30e92527b46.js",
"/js/lang-en.0f790217417404ecc662.js": "/js/lang-en.0f790217417404ecc662.js",
"/js/app.js": "/js/app.js",
"/css/app.css": "/css/app.css"
}
+69 -24
View File
@@ -21,23 +21,27 @@
<el-badge :value="bellBadge > 0 ? bellBadge : ''" class="item">
<el-button icon="el-icon-bell" circle></el-button>
</el-badge>
<el-dropdown-menu slot="dropdown" id="notification">
<div v-for="(item,index) in notification.message">
<a v-on:click.prevent='readNotification(item.id);navigateTo(item.link)'>
<el-dropdown-item>
<b v-if="item.is_read == 0">
{{item.detail}}
</b>
<span v-else >
{{item.detail}}
</span>
<br/>
<span class="opacity80">
{{item.time_interval}}
</span>
</el-dropdown-item>
</a>
<el-dropdown-menu slot="dropdown">
<div id="notification">
<div v-for="(item,index) in notification">
<a v-on:click.prevent='readNotification(item.id);navigateTo(item.link)'>
<el-dropdown-item>
<b v-if="item.is_read == 0">
{{item.detail}}
</b>
<span v-else >
{{item.detail}}
</span>
<br/>
<span class="opacity80">
{{item.time_interval}}
</span>
</el-dropdown-item>
</a>
</div>
</div>
<el-button v-if="pagination.next_page_url != null" id="notification-load-more" v-on:click='fetchPaginateBooking(pagination.next_page_url)'>Load more</el-button>
<div v-else id="notification-load-more"></div>
</el-dropdown-menu>
</el-dropdown>
@@ -96,14 +100,15 @@ export default {
loadingNotification:false,
bellBadge : 0,
unread_message_length:0,
url: '/api/notification/user',
pagination: [],
}),
computed: mapGetters({
user: 'auth/user'
}),
mounted(){
this.getNotification();
this.getNotification(this.url);
},
methods: {
async logout(){
@@ -113,15 +118,16 @@ export default {
// Redirect to login.
this.$router.push({ name: 'login' });
},
getNotification(){
getNotification(url){
this.notification = [];
this.loadingNotification=true;
axios
.get('/api/notification/user/')
.get(url)
.then((response) => {
this.loadingNotification=false;
this.notification = response.data;
this.bellBadge = this.notification.unread_message.length;
this.notification = response.data.message.data;
this.bellBadge = response.data.unread_message.length;
this.makePagination(response.data.message);
console.log(response.data);
}).catch((error) => {
console.log(error)
@@ -130,11 +136,40 @@ export default {
})
})
},
makePagination(data){
let pagination ={
current_page: data.current_page,
last_page: data.last_page,
next_page_url: data.next_page_url,
prev_page_url: data.prev_page_url
};
this.pagination = pagination;
},
fetchPaginateBooking(url) {
this.url = url;
this.loadingNotification=true;
if(this.url !== null){
axios
.get(url)
.then((response) => {
this.loadingNotification=false;
this.notification = this.notification.concat(response.data.message.data);
this.bellBadge = response.data.unread_message.length;
this.makePagination(response.data.message);
console.log(this.notification);
}).catch((error) => {
console.log(error)
this.$router.push({
name: 'notfound'
})
})
}
},
readNotification(notification_id){
axios
.post('/api/notification/read-notification/'+notification_id)
.then((response) => {
this.getNotification();
this.getNotification(this.url);
}).catch((error) => {
console.log(error)
this.$router.push({
@@ -156,9 +191,19 @@ export default {
margin: -.375rem 0;
}
.el-dropdown-menu{
max-height: 50%;
height: 50%;
}
#notification{
overflow-y: scroll;
overflow-x: hidden;
max-height: 100%;
}
#notification-load-more{
position: absolute;
width: 100%;
min-height: 20px;
background: white;
border: 1px solid #dcdfe6;
}
.el-dropdown-menu__item {
line-height: 26px;
-2
View File
@@ -81,7 +81,6 @@ export default {
axios.get(this.url).then(response => {
this.bookingTable = response.data.data;
$this.makePagination(this.bookingTable);
console.log(response.data.data);
})
},
RefreshBooking() {
@@ -106,7 +105,6 @@ export default {
prev_page_url: data.prev_page_url
}
this.pagination = pagination
console.log(this.pagination)
},
fetchPaginateBooking(url) {
this.url = url
+1
View File
@@ -609,6 +609,7 @@ export default {
}
axios.post('api/booking', newBooking)
.then((response) => {
console.log(response);
this.loading = false
// push with return id
this.$router.push({