Skip to content

Commit

Permalink
Added ActivityLog in admin/dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
milanarandjelovic committed Feb 8, 2017
1 parent 747923d commit 26eff33
Show file tree
Hide file tree
Showing 9 changed files with 1,081 additions and 228 deletions.
36 changes: 36 additions & 0 deletions app/Http/Controllers/Admin/ActivityController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use Illuminate\Support\Collection;
use App\Http\Controllers\Controller;
use Spatie\Activitylog\Models\Activity;

class ActivityController extends Controller
{

/**
* @return \Illuminate\Http\JsonResponse
*/
public function activities()
{
$activities = $this->getLatestActivityItems();

return response()->json($activities);
}


/**
* Get all activity for admin dashboard.
*
* @return Collection
*/
public function getLatestActivityItems(): Collection
{
return Activity::with('causer')
->latest()
->limit(30)
->get();
}
}
8 changes: 8 additions & 0 deletions app/Http/Controllers/Auth/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ protected function create(array $data)
'password' => bcrypt($data['password']),
]);

activity()->by($user->id)
->performedOn($user)
->withProperties([
'type' => 'user',
'title' => $user->username,
])
->log('New user has been registered.');

$user_id = $user->id;
$roles = Role::all()->where('name', 'user')->first();
$role_id = $roles->id;
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Forum/DiscussionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function store(DiscussionRequest $request)
->withProperties([
'type' => 'discussion',
'title' => $discussion->title,
'link' => 'discuss/channels/' . $channel->channel_url . '/' . $discussion->slug,
'link' => '/discuss/channels/' . $channel->channel_url . '/' . $discussion->slug,
])
->log('Create discussion');

Expand Down
1,141 changes: 916 additions & 225 deletions public/js/app.js

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion resources/assets/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ import DiscussionComments from './vuejs/components/forum/DiscussionComments.vue'
/* Search component */
import ForumSearch from './vuejs/components/forum/ForumSearch.vue';

/* Dashboard component */
import ActivityLog from './vuejs/components/admin/dashboard/Activitylog.vue';


const app = new Vue({
el: '#app',

Expand All @@ -58,6 +62,7 @@ const app = new Vue({
AdminRole,
CommentVote,
ForumSearch,
DiscussionComments
DiscussionComments,
ActivityLog
}
});
5 changes: 5 additions & 0 deletions resources/assets/js/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ window._ = require('lodash');

window.$ = window.jQuery = require('jquery');
window.axios = require('axios');
window.moment = require('moment')
require('bootstrap-sass');
require('metismenu');
require('jquery-slimscroll');
Expand All @@ -25,6 +26,10 @@ require('./plugins/main');
window.Vue = require('vue');
require('vue-resource');

Vue.filter('timeago', function(value) {
return moment.utc(value).local().fromNow();
});

/**
* We'll register a HTTP interceptor to attach the "CSRF" header to each of
* the outgoing requests issued by this application. The CSRF middleware
Expand Down
105 changes: 105 additions & 0 deletions resources/assets/js/vuejs/components/admin/dashboard/Activitylog.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<template>
<div id="activity-log">

<scale-loader
class="admin-scale-loader"
:loading="loading"
:color="color"
:height="height"
:width="width"
:margin="margin"
>
</scale-loader>

<div class="ibox" v-show="!loading">

<div class="ibox-title">
<h5>Activities in forum</h5>
</div> <!-- /.ibox-title -->

<div class="ibox-content">

<!-- ACTIVITYLOG TABLE -->
<div class="table-responsive" v-show="!loading">
<div class="dataTables_wrapper form-inline dt-bootstrap">
<table class="table table-striped table-bordered table-hover dataTable dtr-inline">
<thead>
<tr>
<th>#</th>
<th>Time</th>
<th>Description</th>
<th>User</th>
</tr>
</thead>
<tbody>
<tr v-for="activity in activities">
<td>{{ activity.id }}</td>
<td>{{ activity.created_at | timeago }}</td>
<td>
<span v-if="activity.properties.type == 'user'">
{{ activity.description }}
</span>
<span v-else>
{{ activity.description }}
<a :href="activity.properties.link">"{{ activity.properties.title }}"</a>
</span>
</td>
<td>
<a :href="'/@' + activity.causer.username">{{ activity.causer.username }}</a>
</td>
</tr>
</tbody>
</table>

</div> <!-- /.dataTables_wrapper-->
</div> <!-- /.table-responsive -->
<!-- /ACTIVITYLOG TABLE -->

</div> <!-- /.ibox-content -->
</div> <!-- /.ibox -->

</div>
</template>

<script>
import ScaleLoader from 'vue-spinner/src/ScaleLoader.vue'
export default {
name: 'activity-log',
data () {
return {
height: '60px',
activities: []
}
}, // data()
components: {
'scale-loader': ScaleLoader
}, // components
beforeMount () {
this.loading = true
}, // beforeMount()
mounted () {
this.loading = false
this.getAllActivities()
}, // mounted()
methods: {
getAllActivities () {
axios.get('/api/admin/activities')
.then((response) => {
console.log(response)
this.activities = response.data
})
.catch((error) => {
})
} // getAllActivities()
} // methods
}
</script>

<style lang="css">
</style>
2 changes: 1 addition & 1 deletion resources/views/admin/dashboard/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
@section('title', '| Dashboard')

@section('content')

<activity-log></activity-log>
@endsection
3 changes: 3 additions & 0 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
Route::get('/discussions/{discussion}/comments', 'Forum\DiscussionCommentController@index');

Route::group(['middleware' => 'auth:api', 'prefix' => 'admin'], function () {
/* Dashboard routes */
Route::get('/activities', 'Admin\ActivityController@activities');

/* Channels routes */
Route::post('channels/store', 'Admin\ChannelController@store');
Route::get('channels', 'Admin\ChannelController@channels');
Expand Down

0 comments on commit 26eff33

Please sign in to comment.