Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add select to version tab #371

Open
wants to merge 1 commit into
base: main
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
53 changes: 52 additions & 1 deletion app/controllers/ModController.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,57 @@ public function postDelete($mod_id = null)
return Redirect::to('mod/list')->with('success','Mod deleted!');
}

public function getFileRefresh($mod_id = null)
{
if (Request::ajax())
{
if (empty($mod_id))
return Response::json(array(
'status' => 'error',
'reason' => 'Missing Post Data'
));

$mod = Mod::find($mod_id);
if (empty($mod))
return Response::json(array(
'status' => 'error',
'reason' => 'Could not pull mod from database'
));
$location = Config::get('solder.repo_location').'mods/'.$mod->name.'/';
if(!file_exists($location))
return Response::json(array(
'status' => 'error',
'reason' => 'Folder '.$mod->name.' does not exist.'
));
$files = scandir($location);
if(!$files)
return Response::json(array(
'status' => 'error',
'reason' => 'Could not find mod folder'
));
$existingVersionsObjects = $mod->versions()->get();
$existingVersions = array();
foreach ($existingVersionsObjects as $i => $version) {
$existingVersions[] = $version->version;
}
$versions = array();
foreach ($files as $i => $file) {
if(strpos($file, ".zip") !== false) {
$version = str_replace(".zip", "", str_replace($mod->name."-", "", $file));
if(!in_array($version, $existingVersions)) {
$versions[] = $version;
}
}
}
return Response::json(array(
'versions' => $versions,
'status' => 'success'
));

}
return App::abort(404);
}

public function getRehash($ver_id = null)
{
if (Request::ajax())
Expand Down Expand Up @@ -269,4 +320,4 @@ private function remote_mod_md5($mod, $version, $attempts = 0)
return $this->remote_mod_md5($mod, $version, $attempts + 1);
}
}
}
}
58 changes: 51 additions & 7 deletions app/views/mod/view.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,11 @@
<input type="hidden" name="mod-id" value="{{ $mod->id }}">
<td></td>
<td>
<input type="text" name="add-version" id="add-version" class="form-control"></td>
<select type="text" name="add-version" id="add-version" class="form-control" /></td>
<td>N/A</td>
<td><span id="add-url">N/A</span></td>
<td><button type="submit" class="btn btn-success btn-small add">Add Version</button></td>
<td><button type="submit" class="btn btn-success btn-small add">Add Version</button>
<button id="refresh" class="btn btn-primary btn-small"><i id="refresh-icon" class="fa fa-refresh"></i></button></td>
</form>
</tr>
@foreach ($mod->versions()->orderBy('id', 'desc')->get() as $ver)
Expand Down Expand Up @@ -120,9 +121,44 @@
@endsection
@section('bottom')
<script type="text/javascript">
function refresh() {
$('#refresh-icon').addClass("fa-spin");
$.ajax({
type: "GET",
url: "{{ URL::to('mod/file-refresh/'.$mod->id) }}",
success: function (data) {
$('#refresh-icon').removeClass("fa-spin");
if (data.status == "success") {
$('#add-version').empty();
if(data.versions.length > 0) {
$('#add-version').append('<option value=\"\">Select Version</option>');
$.each(data.versions,function(key, value)
{
$('#add-version').append('<option value=' + value + '>' + value + '</option>');
if(data.versions.length == key -1)
$("#add-url").html('<a href="{{ Config::get("solder.mirror_url") }}mods/{{ $mod->name }}/{{ $mod->name }}-' + $(this).val() + '.zip" target="_blank">{{ Config::get("solder.mirror_url") }}mods/{{ $mod->name }}/{{ $mod->name }}-' + $(this).val() + '.zip</a>');
});
} else {
$('#add-version').append('<option value=\"\">N/A</option>');
$("#add-url").html('N/A');
}
} else {
$("#danger-ajax").stop(true, true).html('Error: ' + data.reason).fadeIn().delay(3000).fadeOut();
}
},
error: function (xhr, textStatus, errorThrown) {
$('#refresh-icon').removeClass("fa-spin");
$("#danger-ajax").stop(true, true).html(textStatus + ': ' + errorThrown).fadeIn().delay(3000).fadeOut();
}
});
}

$('#add-version').keyup(function() {
$("#add-url").html('<a href="{{ Config::get("solder.mirror_url") }}mods/{{ $mod->name }}/{{ $mod->name }}-' + $(this).val() + '.zip" target="_blank">{{ Config::get("solder.mirror_url") }}mods/{{ $mod->name }}/{{ $mod->name }}-' + $(this).val() + '.zip</a>');
$('#add-version').change(function() {
if ($('#add-version').val() != "") {
$("#add-url").html('<a href="{{ Config::get("solder.mirror_url") }}mods/{{ $mod->name }}/{{ $mod->name }}-' + $(this).val() + '.zip" target="_blank">{{ Config::get("solder.mirror_url") }}mods/{{ $mod->name }}/{{ $mod->name }}-' + $(this).val() + '.zip</a>');
} else {
$("#add-url").html('N/A');
}
});

$('#add').submit(function(e) {
Expand All @@ -135,6 +171,7 @@
data: $("#add").serialize(),
success: function (data) {
if (data.status == "success") {
refresh();
$("#add-row").after('<tr><td></td><td>' + data.version + '</td><td>' + data.md5 + '</td><td><a href="{{ Config::get("solder.mirror_url") }}mods/{{ $mod->name }}/{{ $mod->name }}-' + data.version + '.zip" target="_blank">{{ Config::get("solder.mirror_url") }}mods/{{ $mod->name }}/{{ $mod->name }}-' + data.version + '.zip</a></td><td></td></tr>');
$("#success-ajax").stop(true, true).html('Added mod version at ' + data.version).fadeIn().delay(3000).fadeOut();
} else {
Expand All @@ -144,10 +181,15 @@
error: function (xhr, textStatus, errorThrown) {
$("#danger-ajax").stop(true, true).html(textStatus + ': ' + errorThrown).fadeIn().delay(3000).fadeOut();
}
})
});
}
});

$('#refresh').click(function(e) {
e.preventDefault();
refresh();
});

$('.version-icon').click(function() {
$('.version-details[rel=' + $(this).attr('rel') + "]").toggle(function() {
$('.version-icon[rel=' + $(this).attr('rel') + "]").toggleClass("fa-minus");
Expand Down Expand Up @@ -182,6 +224,7 @@
url: "{{ URL::to('mod/delete-version/') }}/" + $(this).attr('rel'),
success: function (data) {
if (data.status == "success") {
refresh();
$('.version[rel=' + data.version_id + ']').fadeOut();
$('.version-details[rel=' + data.version_id + ']').fadeOut();
$("#success-ajax").stop(true, true).html('Mod version ' + data.version + ' deleted.').fadeIn().delay(3000).fadeOut();
Expand All @@ -196,6 +239,7 @@
});

$(document).ready(function() {
refresh();
var tab = window.location.hash.substr(1);

if (tab == "versions") {
Expand All @@ -206,7 +250,7 @@

/* Disabled for now, there is ample screen space that all we need to do is switch the tabs
changing location is disorienting.

$('#tabs a[href="#versions"]').click(function() {
window.location.hash = "#versions";
});
Expand All @@ -217,4 +261,4 @@
});

</script>
@endsection
@endsection