Skip to content
This repository has been archived by the owner on Feb 9, 2021. It is now read-only.

Clickable metrics #213

Open
wants to merge 2 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
2 changes: 1 addition & 1 deletion app/Model/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ public static function resolveId()
public function hasRole($role)
{
if (is_string($role)) {
$class = sprintf('App\Classes\Roles\%s', $role);
$class = sprintf('App\Classes\Roles\%s', ucfirst($role));

return $this->hasRole(app()->make($class));
}
Expand Down
24 changes: 23 additions & 1 deletion app/Model/Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
use App\Model\Concerns\Publishers;
use Illuminate\Support\Collection;
use App\Model\Concerns\ActivityFeed;
use App\Modules\Metrics\Models\Clicks;
use App\Modules\Metrics\ClickableTrait;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Relations\MorphOne;

Expand All @@ -31,6 +33,8 @@
* @property Page $page
* @property Menu $children
*
* @property Clicks $clicks
*
* @property Carbon $deleted_at
* @property Carbon $created_at
* @property Carbon $updated_at
Expand All @@ -39,6 +43,7 @@ class Menu extends Model implements Linker
{
/*
* Laravel Deleting.
*
* @ https://laravel.com/docs/5.5/eloquent#soft-deleting
*/
use SoftDeletes;
Expand All @@ -51,7 +56,7 @@ class Menu extends Model implements Linker
/*
* Log the author and editor of the model
*
* @ Webshelf framework 5.6
* @ Webshelf framework 5.1
*/
use Publishers;
/*
Expand All @@ -60,6 +65,12 @@ class Menu extends Model implements Linker
* @ https://laravel.com/docs/5.3/scout#installation
*/
use Searchable;
/*
* Clickable Model Trait for metric tracking.
*
* @ Webshelf Framework 5.3.1
*/
use ClickableTrait;

/**
* Status if current menu.
Expand Down Expand Up @@ -176,4 +187,15 @@ public function name()
{
return $this->title;
}

/**
* Get the first menu with the title name.
*
* @param string $title
* @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|null|object
*/
public static function firstByTitle(string $title)
{
return self::query()->where('title', $title)->first();
}
}
16 changes: 16 additions & 0 deletions app/Modules/Metrics/Assets/click-nav-item.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

$(document).ready(function() {
$(".nav-item").click(function(e) {
console.log("User has clicked on the menu link");

let clicked = 'metrics/clicked/navigation/' + $(this).text();

window.axios.get(clicked).then((response)=>{
console.log(response)
console.log(error.response.data)
}).catch((error)=>{
})
});

e.preventDefault();
});
23 changes: 23 additions & 0 deletions app/Modules/Metrics/ClickableController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
/**
* Created by PhpStorm.
* User: markhester
* Date: 06/09/2018
* Time: 14:21.
*/

namespace App\Modules\Metrics;

/**
* Class ClickableController.
*/
class ClickableController
{
/**
* @param string $button
*/
public function navigation(string $title)
{
//
}
}
26 changes: 26 additions & 0 deletions app/Modules/Metrics/ClickableTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
/**
* Created by PhpStorm.
* User: markhester
* Date: 08/09/2018
* Time: 17:41.
*/

namespace App\Modules\Metrics;

use App\Modules\Metrics\Models\Clicks;
use Illuminate\Database\Eloquent\Relations\MorphMany;

/**
* Trait ClickableTrait.
*/
trait ClickableTrait
{
/**
* @return Clicks|MorphMany
*/
public function clicks()
{
return $this->morphMany(Clicks::class, 'clickable');
}
}
28 changes: 28 additions & 0 deletions app/Modules/Metrics/Models/Clicks.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace App\Modules\Metrics\Models;

/**
* Trait Clicks.
*
* @property int $clicks
*/
class Clicks extends \Illuminate\Database\Eloquent\Model
{
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'metric_clicks';

/**
* Get all the viewable models.
*
* @return \Illuminate\Database\Eloquent\Relations\MorphTo
*/
public function clickable()
{
return $this->morphTo();
}
}
Empty file.
5 changes: 5 additions & 0 deletions app/Modules/Metrics/Routes/frontend.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

use Illuminate\Support\Facades\Route;

Route::get('metrics/clicked/navigation/{menu}', 'ClickableController@navigation');
43 changes: 43 additions & 0 deletions database/migrations/2018_09_08_172507_create_clickable_models.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateClickableModels extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('metric_clicks', function (Blueprint $table) {
$table->integer('id');
$table->unsignedInteger('clickable_id');
$table->string('clickable_type');
$table->integer('clicks');
$table->timestamp('created_at');
});

// Schema::create('metric_views', function(Blueprint $table) {
// $table->integer('id');
// $table->unsignedInteger('viewable_id');
// $table->string('viewable_type');
// $table->integer('views');
// $table->timestamp('created_at');
// });
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('metric_clicks');
// Schema::drop('metric_views');
}
}
17,445 changes: 17,430 additions & 15 deletions public/assets/backend.css

Large diffs are not rendered by default.

96,217 changes: 96,216 additions & 1 deletion public/assets/backend.js

Large diffs are not rendered by default.

13,544 changes: 13,538 additions & 6 deletions public/assets/frontend.css

Large diffs are not rendered by default.

47,206 changes: 47,205 additions & 1 deletion public/assets/frontend.js

Large diffs are not rendered by default.

Empty file added public/assets/modules.css
Empty file.
15 changes: 15 additions & 0 deletions public/assets/modules.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

$(document).ready(function() {
$(".nav-item").click(function(e) {
console.log("User has clicked on the menu link");
e.preventDefault();

let clicked = 'metrics/clicked/navigation/' + $(this).text();

window.axios.get(clicked).then((response)=>{
console.log(response)
}).catch((error)=>{
console.log(error.response.data)
})
});
});
10 changes: 6 additions & 4 deletions public/mix-manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"/assets/backend.js": "/assets/backend.js?id=316e0c5a5a24607e4ea0",
"/assets/frontend.js": "/assets/frontend.js?id=49f7246436891e3f47cc",
"/assets/frontend.css": "/assets/frontend.css?id=088b8ef5ba320563750c",
"/assets/backend.css": "/assets/backend.css?id=aaff7d70e828dedf4903"
"/assets/backend.js": "/assets/backend.js?id=3e87f01e0f837bc2cdfc",
"/assets/frontend.js": "/assets/frontend.js?id=2c306df51db4003cb016",
"/assets/frontend.css": "/assets/frontend.css?id=99aeaa668dd0901b44ad",
"/assets/backend.css": "/assets/backend.css?id=64576f0b79c522b6482c",
"/assets/modules.js": "/assets/modules.js?id=aec690b3c783b7d01c04",
"/assets/modules.css": "/assets/modules.css?id=d41d8cd98f00b204e980"
}
4 changes: 3 additions & 1 deletion resources/templates/master.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
{{-- Normal page loading meta tags. --}}
<title>@yield("webpage.title", $webpage->title())</title>
<meta name="csrf-token" content="{{ csrf_token() }}">
<meta name="keywords" value="@yield('webpage.keywords', $webpage->keywords())">
<meta name="keywords" value=``"@yield('webpage.keywords', $webpage->keywords())">
<meta name="description" value="@yield('webpage.description', $webpage->description())">

{{-- Favicon Image Icon --}}
Expand All @@ -23,10 +23,12 @@

{{-- Styles --}}
<link href="{{ mix('assets/frontend.css') }}" rel="stylesheet">
<!-- <link href="{{ mix('assets/modules.css') }}" rel="stylesheet"> -->
@stack("styles")

{{-- Scripts --}}
<script src="{{ mix('assets/frontend.js') }}"></script>
<script src="{{ mix('assets/modules.js') }}"></script>
@stack("scripts")

{{-- Google analytics tracking --}}
Expand Down
13 changes: 13 additions & 0 deletions resources/templates/navigation.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<div class="menu {{$class ?? ''}}">

<ul>

@foreach($webpage->navigation->main() as $menu)

<li><a href="{{ $menu->route() }}" class="nav-item {{ $menu->classState() }}" target="{{ $menu->target }}">{{ $menu->title }}</a></li>

@endforeach

</ul>

</div>
6 changes: 1 addition & 5 deletions resources/views/frame.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,7 @@
<div class="flex-center position-ref full-height">
@if (Route::has('login'))
<div class="top-right links">
@auth
<a href="{{ url('/index') }}">Home</a>
@else
<a href="{{ route('login') }}">Login</a>
@endauth
@extends("webpage::navigation")
</div>
@endif

Expand Down
5 changes: 4 additions & 1 deletion webpack.mix.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ const mix = require('laravel-mix');
| file for the application as well as bundling up all the JS files.
|
*/

mix.js('resources/assets/js/frontend.js', 'public/assets/')
.sass('resources/assets/sass/frontend.scss', 'public/assets/')
.version();

// Lets combine the module assets to the output frontend.js so its loaded as one location.
mix.combine(['app/Modules/*/Assets/*.js'], 'public/assets/modules.js');
mix.combine(['app/Modules/*/Assets/*.css'], 'public/assets/modules.css');

/*
|--------------------------------------------------------------------------
| Back End Asset Management
Expand Down