-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
331 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class CabangNode extends Model | ||
{ | ||
use HasFactory; | ||
|
||
protected $fillable = [ | ||
'cabang_id', | ||
'root_id', | ||
]; | ||
|
||
public function cabang() | ||
{ | ||
return $this->belongsTo(Cabang::class); | ||
} | ||
|
||
public function root() | ||
{ | ||
return $this->belongsTo(CabangNode::class); | ||
} | ||
|
||
public function children() | ||
{ | ||
return $this->hasMany(CabangNode::class, 'root_id'); | ||
} | ||
|
||
public static function getTree($rootId = null) | ||
{ | ||
if ($rootId === null) { | ||
$roots = CabangNode::with('cabang', 'children')->whereNull('root_id')->get(); | ||
if ($roots->count() == 0) { | ||
return null; | ||
} | ||
|
||
return $roots->map(function ($root) { | ||
return [ | ||
'id' => (string)$root->id, | ||
'data' => [ | ||
'name' => $root->cabang->nama, | ||
], | ||
'children' => $root->children->count() > 0 ? $root->children->map(function () use ($root) { | ||
return CabangNode::getTree($root->id); | ||
}) : null, | ||
]; | ||
}); | ||
} | ||
$root = CabangNode::with('cabang', 'children')->where('root_id', $rootId)->first(); | ||
if (!$root) { | ||
return null; | ||
} | ||
|
||
$result = [ | ||
'id' => (string)$root->id, | ||
'data' => [ | ||
'name' => $root->cabang->nama, | ||
], | ||
'children' => $root->children->count() > 0 ? $root->children->map(function () use ($root) { | ||
return CabangNode::getTree($root->id); | ||
}) : null, | ||
]; | ||
if ($result["children"] === null) { | ||
unset($result["children"]); | ||
} | ||
return $result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
database/migrations/2025_01_27_110853_create_cabang_nodes_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
return new class extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
*/ | ||
public function up(): void | ||
{ | ||
Schema::create('cabang_nodes', function (Blueprint $table) { | ||
$table->id(); | ||
$table->foreignId('cabang_id')->constrained('cabangs')->cascadeOnDelete(); | ||
$table->foreignId('root_id')->nullable()->constrained('cabang_nodes')->cascadeOnDelete(); | ||
$table->timestamps(); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
*/ | ||
public function down(): void | ||
{ | ||
Schema::dropIfExists('cabang_nodes'); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,9 +59,12 @@ class="resize-none flex-grow p-2 border-2 border-slate-400 rounded-s-md" | |
<select name="task" id="task" class="flex-grow p-2 border-2 border-slate-400 rounded-s-md"> | ||
<option value="">Pilih Tugas</option> | ||
@foreach ($tasks as $task) | ||
<option value="{{ $task->id }}">{{ $task->deskripsi }}</option> | ||
<option value="{{ $task->id }}" data-doc="{{ $task->berkas }}">{{ $task->deskripsi }} | ||
</option> | ||
@endforeach | ||
</select> | ||
<a href="" id="doc-url" class="hidden text-blue-500 underline" target="_blank">Lihat | ||
Dokumen</a> | ||
<label for="url">Berkas</label> | ||
<div class="flex w-full"> | ||
<input type="text" name="url" id="url" | ||
|
@@ -84,6 +87,7 @@ class="bg-[#003285] opacity-80 hover:opacity-100 duration-200 text-white px-2 py | |
<div class="flex flex-col px-4 py-2 gap-2"> | ||
@foreach ($konseps as $konsep) | ||
<div class="w-full"> | ||
<h1>{{ $konsep->task->deskripsi }}</h1> | ||
<a href="{{ $konsep->berkas }}" class="w-full flex gap-2" target="_blank">{{ $konsep->name }} <svg | ||
class="w-6 h-6 text-gray-800 dark:text-white" aria-hidden="true" | ||
xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" | ||
|
@@ -92,9 +96,9 @@ class="w-6 h-6 text-gray-800 dark:text-white" aria-hidden="true" | |
d="M18 14v4.833A1.166 1.166 0 0 1 16.833 20H5.167A1.167 1.167 0 0 1 4 18.833V7.167A1.166 1.166 0 0 1 5.167 6h4.618m4.447-2H20v5.768m-7.889 2.121 7.778-7.778" /> | ||
</svg> | ||
</a> | ||
<iframe> | ||
{{-- <iframe> | ||
<embed class="w-full h-[60vh]" src="{{ $konsep->berkas }}" frameborder="0"></embed> | ||
</iframe> | ||
</iframe> --}} | ||
</div> | ||
@endforeach | ||
</div> | ||
|
@@ -103,6 +107,18 @@ class="w-6 h-6 text-gray-800 dark:text-white" aria-hidden="true" | |
<script src="/script/nav.js"></script> | ||
<script src="/script/chatbot.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/flowbite.min.js"></script> | ||
<script> | ||
document.querySelector("#task").addEventListener("change", function() { | ||
var doc = this.options[this.selectedIndex].getAttribute("data-doc"); | ||
if (doc) { | ||
document.querySelector("#doc-url").classList.remove("hidden"); | ||
document.querySelector("#doc-url").href = doc; | ||
} else { | ||
document.querySelector("#doc-url").classList.add("hidden"); | ||
document.querySelector("#doc-url").href = ""; | ||
} | ||
}); | ||
</script> | ||
<script> | ||
document | ||
.querySelector(`#url_set`) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
<!DOCTYPE html> | ||
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}"> | ||
|
||
<head> | ||
@include('components/head') | ||
<title>Air Mutasi | Profil</title> | ||
</head> | ||
|
||
<body class="font-sans tracking-wider"> | ||
@include('components/header', ['static' => true]) | ||
@include('components.modal-component') | ||
<main class="px-8 py-16"> | ||
<div> | ||
<select id="tambah-select-cabang"> | ||
@foreach ($cabangs as $cabang) | ||
<option value="{{ $cabang->id }}">{{ $cabang->nama }}</option> | ||
@endforeach | ||
</select> | ||
<button onclick="tambah()">Tambah</button> | ||
</div> | ||
<div id="nodes"> | ||
@foreach ($nodes as $node) | ||
<div class="flex items-center justify-between" id="node-{{ $node->cabang_id }}"> | ||
<p class="text-lg font-bold">{{ $node->cabang->nama }}</p> | ||
<aside> | ||
<select> | ||
<option value="">PUSAT</option> | ||
@foreach ($nodes as $snode) | ||
<option value="{{ $snode->id }}" @if ($node->root_id == $snode->id) selected @endif> | ||
{{ $snode->cabang->nama }} | ||
</option> | ||
@endforeach | ||
</select> | ||
<button onclick="edit({{ $node->cabang_id }})">Simpan</button> | ||
<button onclick="hapus({{ $node->cabang_id }})">Hapus</button> | ||
</aside> | ||
</div> | ||
@endforeach | ||
</div> | ||
</main> | ||
<template id="node-template"> | ||
<p class="text-lg font-bold" id="nama"></p> | ||
<aside> | ||
<select> | ||
<option value="">PUSAT</option> | ||
@foreach ($nodes as $snode) | ||
<option value="{{ $snode->id }}"> | ||
{{ $snode->cabang->nama }} | ||
</option> | ||
@endforeach | ||
</select> | ||
<button id="simpan">Simpan</button> | ||
<button id="hapus">Hapus</button> | ||
</aside> | ||
</template> | ||
@include('components.footer') | ||
<script src="/script/nav.js"></script> | ||
<script src="/script/chatbot.js"></script> | ||
<script> | ||
function edit(id) { | ||
const cabang_id = id; | ||
const root_id = document.getElementById(`node-${id}`).querySelector('select').value; | ||
fetch("/api/struktur-cabang/edit", { | ||
method: 'POST', | ||
headers: { | ||
'Accept': 'application/json', | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ | ||
cabang_id, | ||
root_id: parseInt(root_id), | ||
}) | ||
}).then(response => response.json()) | ||
.then(data => { | ||
console.log(data); | ||
alert('Berhasil disimpan'); | ||
}) | ||
.catch(error => console.error(error)); | ||
} | ||
function hapus(id) { | ||
const cabang_id = id; | ||
fetch("/api/struktur-cabang/delete/" + cabang_id, { | ||
method: 'DELETE', | ||
headers: { | ||
'Accept': 'application/json', | ||
'Content-Type': 'application/json', | ||
}, | ||
}).then(response => response.json()) | ||
.then(data => { | ||
console.log(data); | ||
window.location.reload(); | ||
}) | ||
.catch(error => console.error(error)); | ||
} | ||
function tambah() { | ||
const nodes = document.getElementById('nodes'); | ||
const selected_cabang = document.getElementById('tambah-select-cabang').value; | ||
const is_exists = document.getElementById(`node-${selected_cabang}`); | ||
if (is_exists) { | ||
alert('Cabang sudah ada'); | ||
return; | ||
} | ||
const nodeTemplate = document.getElementById('node-template').content.cloneNode(true); | ||
nodeTemplate.querySelector('#nama').textContent = document.querySelector( | ||
'#tambah-select-cabang > option:checked').textContent; | ||
nodeTemplate.querySelector("#simpan").onclick = () => edit(selected_cabang); | ||
nodeTemplate.querySelector("#hapus").onclick = () => hapus(selected_cabang); | ||
const item = document.createElement('div'); | ||
item.classList.add('flex', 'items-center', 'justify-between'); | ||
item.id = `node-${selected_cabang}`; | ||
item.appendChild(nodeTemplate); | ||
nodes.appendChild(item); | ||
} | ||
</script> | ||
</body> |
Oops, something went wrong.