Skip to content

Commit

Permalink
Merge pull request #8 from priatmoko/user-profile
Browse files Browse the repository at this point in the history
User profile
  • Loading branch information
priatmoko authored May 27, 2019
2 parents 0a94bee + 55d2b5e commit fae4842
Show file tree
Hide file tree
Showing 15 changed files with 577 additions and 8 deletions.
52 changes: 52 additions & 0 deletions app/Http/Controllers/Admin/Apps/FormController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace App\Http\Controllers\Admin\Apps;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

/**loading models */
use App\Models\Apps;

class FormController extends Controller
{
/**
* Displaying create menu
*/
public function create()
{
$breadcrumb = ['Application Management'=>route('apps'), 'Register New Application'=>''];
$title = 'Register New Application';
return view('Admin.Apps.create')
->with('breadcrumb', $breadcrumb)
->with('title', $title);
}
/**
* Store data
* @param void object laravel Request
* @return string json
*/
public function store(Request $r)
{
//validate before saving
$validation = \Validator::make($r->all(),[
'name'=>'required',
'url'=>'required',]);

if ($validation->fails())
return response()->json(['errors'=>$validation->errors()], 422);
$apps = new Apps;
$apps->name = $r->input('name');
$apps->parent = $r->input('parent');
$apps->node_name = $r->input('node_name');
$apps->url = $r->input('url');
$apps->color = $r->input('color');
$apps->icon = $r->input('icon');
$apps->desc = $r->input('desc');
$apps->sorter = $r->input('sorter');
$apps->save();

return response()->json(['status'=>'success']);
}

}
37 changes: 37 additions & 0 deletions app/Http/Controllers/Admin/Apps/IndexController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace App\Http\Controllers\Admin\Apps;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

/**loading models */
use App\Models\Apps;

class IndexController extends Controller
{
/**
* Displaying main panel of application management
* @return void displaying main panel of Application management
*/
public function index()
{
$breadcrumb = ['Application Management'=>''];
$title = 'Application Management';
return view('Admin.Apps.index')
->with('title', $title)
->with('breadcrumb', $breadcrumb);
}
/**
* Getting list of registered Application
*/
public function getList(Request $r)
{
$apps = Apps::where('name', 'like', '%'.$r->input('name').'%')
->get();
if (is_object($apps) && count($apps)>0)
return response()->json(['status'=>'success', 'd'=>$apps]);
else
return response()->json(['status'=>'fail']);
}
}
6 changes: 3 additions & 3 deletions app/Http/Controllers/Admin/Profile/FormController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public function store(Request $r)
$validation =\Validator::make($r->all(), [
'name'=>'required|max:191',
'id'=>'required',
'username'=>'required',
'email'=>'required|email',
'username'=>'required|alpha_dash',
'email'=>'required|email|unique:users,email,'.$r->input('id'),
'avatar'=>'image|max:1024']);
//check validataion result
if ($validation->fails())
Expand Down Expand Up @@ -79,7 +79,7 @@ private function moveFile($file, $filename, $path, $user)
if (file_exists($path.$filename))
unlink($path.$filename);
//check the existing file refer to exist data
if (file_exists($path.$user->avatar))
if ($user->avatar!="" && file_exists($path.$user->avatar))
unlink($path.$user->avatar);
//check the existing file refer to exist data (thumbnail)
if (file_exists($path.'thumb-'.$user->avatar))
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Auth/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ protected function validator(array $data)
{
return Validator::make($data, [
'name' => ['required', 'string', 'max:255'],
'username' => ['required', 'string', 'max:255', 'unique:users'],
'username' => ['required', 'string', 'alpha_dash ', 'max:255', 'unique:users'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
'password' => ['required', 'string', 'min:8', 'confirmed'],
]);
Expand Down
10 changes: 10 additions & 0 deletions app/Models/Apps.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Apps extends Model
{

}
39 changes: 39 additions & 0 deletions database/migrations/2019_05_02_064742_create_apps_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

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

class CreateAppsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('apps', function (Blueprint $table) {
$table->bigIncrements('id');
$table->bigInteger('parent')->nullable();
$table->integer('sorter')->nullable();
$table->string('name');
$table->string('node_name')->nullable();
$table->mediumText('desc')->nullable();
$table->string('url');
$table->string('color')->nullable();
$table->string('icon')->nullable();
$table->timestamps();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('apps');
}
}
32 changes: 32 additions & 0 deletions public/assets/Admin/Apps/create.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* initialize event on creating menu management features
*/
var init = function(){
$('#app-form').submit(function(e){
e.preventDefault();
saveApps();
});
}
var saveApps = function(){
if ($('#app-form').postValidate()===false){
return false;
}
$('#app-form').postAjax({
success:function(r){
console.log(r);
if (r.status=="success"){
iziToast.success({
title: 'INFO !',
message: 'Operation success, data has been saved',
position: 'topRight'
});
}else{
iziToast.error({
title: 'INFO !',
message: 'Operation failed, please check the data input',
position: 'topRight'
});
}
}
});
}
60 changes: 60 additions & 0 deletions public/assets/Admin/Apps/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* Initial event
*/
var init = function(){
$('#app-index').submit(function(e){
e.preventDefault();
displayIndex();
});
}
/**
* displaying list of registered application
*/
var displayIndex = function(){
$('#app-index').postAjax({
success:function(r){

if (r.status=="success"){
injectTable(r.d);
}else{
iziToast.error({
title: 'Not Found !',
message: 'Please try other keywords',
position: 'topRight'
});
}
}
});
}

var injectTable = function(obj){

var tr = "";
var td = $('#table-apps thead tr th');
var tbody = $('#table-apps tbody');
$.each(obj, function(i, v) {
datas = "";
$.each(v, function(id, iv) {
datas += 'data-' + id + '="' + iv + '"';
});
tr += "<tr id='act_" + i + "' " + datas + " class='context-menu' title='Right Click to choose operation. &#013;Sequence : &#013;"+v.caseqn+"'>";
$.each(td, function(index, field) {
tr += "<td style='" + $(this).attr('style') + "' class='" + $(this).attr('class') + "'>";
if ($(this).data('field')=='icon'){
if (v[$(this).data('field')]==null)
tr += "<i class='fa fa-th'></i>";
else
tr += "<i class='fa "+v[$(this).data('field')]+"'></i>";
}else{
if (v[$(this).data('field')]==null)
tr += '-';
else
tr += v[$(this).data('field')];
}

tr += "</td>";
});
tr += "</tr>";
});
tbody.html(tr);
}
Loading

0 comments on commit fae4842

Please sign in to comment.