Skip to content

Instantly share code, notes, and snippets.

@krusynth
Last active August 22, 2017 16:27
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krusynth/1aa0213eb9f097bc49f7 to your computer and use it in GitHub Desktop.
Save krusynth/1aa0213eb9f097bc49f7 to your computer and use it in GitHub Desktop.
Hack to use Ajax to rehash all mods in Technic Solder. Replaces app/views/mod/list.blade.php
@extends('layouts/master')
@section('title')
<title>Mod Library - TechnicSolder</title>
@stop
@section('content')
<div class="page-header">
<h1>Mod Library</h1>
</div>
<div class="panel panel-default">
<div class="panel-heading">
<div class="pull-right">
<a id="rehash-all" class="btn btn-xs btn-info">Rehash All</a>
<a href="{{ URL::to('mod/create') }}" class="btn btn-xs btn-success">Add Mod</a>
</div>
Mod List
</div>
<div class="alert alert-success" id="success-ajax" style="width: 100%;display: none"></div>
<div class="alert alert-warning" id="warning-ajax" style="width: 100%;display: none"></div>
<div class="alert alert-danger" id="danger-ajax" style="width: 100%;display: none"></div>
<div class="panel-body">
@if (Session::has('success'))
<div class="alert alert-success">
{{ Session::get('success') }}
</div>
@endif
@if ($errors->all())
<div class="alert alert-danger">
@foreach ($errors->all() as $error)
{{ $error }}<br />
@endforeach
</div>
@endif
<table class="table table-striped table-bordered table-hover" id="dataTables">
<thead>
<tr>
<th>#</th>
<th>Mod Name</th>
<th>Author</th>
<th>Website</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@foreach ($mods as $mod)
<tr>
<td>{{ HTML::link('mod/view/'.$mod->id, $mod->id) }}</td>
<td>
@if (!empty($mod->pretty_name))
{{ HTML::link('mod/view/'.$mod->id, $mod->pretty_name) }} ({{ $mod->name }})
@else
{{ HTML::link('mod/view/'.$mod->id, $mod->name) }}
@endif
<br/>
<b>Latest Version:</b> {{ !$mod->versions->isEmpty() ? $mod->versions->first()->version : "N/A" }}
</td>
<td>{{ !empty($mod->author) ? $mod->author : "N/A" }}</td>
<td>{{ !empty($mod->link) ? HTML::link($mod->link, $mod->link, array("target" => "_blank")) : "N/A" }}</td>
<td>{{ HTML::link('mod/view/'.$mod->id,'Manage', array("class" => "btn btn-xs btn-primary")) }}</td>
</tr>
@endforeach
</table>
</div>
</div>
@endsection
@section('bottom')
<script type="text/javascript">
$(document).ready(function() {
$('#dataTables').dataTable({
"order": [[ 1, "asc" ]]
});
$('#rehash-all').click(function() {
var running = [];
for(var i in mod_ids) {
running.push( $.post('{{ URL::to('mod/rehash/') }}', {'version-id': mod_ids[i]}) );
}
$.when.apply($, running).done( function() {
$("#success-ajax").stop(true, true).html('MD5 hashing complete.').fadeIn().delay(3000).fadeOut();
});
});
});
var mod_ids = [];
@foreach ($mods as $mod)
mod_ids.push( {{ $mod->id }} );
@endforeach;
</script>
@endsection
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment