Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function getEditImageFeatures($id) {
'rarities' => ['0' => 'Select Rarity'] + Rarity::orderBy('sort', 'DESC')->pluck('name', 'id')->toArray(),
'specieses' => ['0' => 'Select Species'] + Species::orderBy('sort', 'DESC')->pluck('name', 'id')->toArray(),
'subtypes' => Subtype::where('species_id', '=', $image->species_id)->orderBy('sort', 'DESC')->pluck('name', 'id')->toArray(),
'features' => Feature::getDropdownItems(1),
'features' => Feature::getDropdownItems(Auth::user()->hasPower('edit_data'), $image->species_id),
]);
}

Expand Down
15 changes: 14 additions & 1 deletion app/Http/Controllers/Characters/DesignController.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ public function getFeatures($id) {
'specieses' => ['0' => 'Select Species'] + Species::visible()->orderBy('sort', 'DESC')->pluck('name', 'id')->toArray(),
'subtypes' => Subtype::visible()->where('species_id', '=', $r->species_id)->orderBy('sort', 'DESC')->pluck('name', 'id')->toArray(),
'rarities' => ['0' => 'Select Rarity'] + Rarity::orderBy('sort', 'DESC')->pluck('name', 'id')->toArray(),
'features' => Feature::getDropdownItems(),
'features' => Feature::getDropdownItems(Auth::user()->hasPower('edit_data'), $r->species_id),
]);
}

Expand All @@ -254,6 +254,19 @@ public function getFeaturesSubtype(Request $request) {
]);
}

/**
* Shows the edit image trait portion of the modal.
*
* @return \Illuminate\Contracts\Support\Renderable
*/
public function getFeaturesTrait(Request $request) {
$species = $request->input('species');

return view('character.design._features_trait', [
'features' => Feature::getDropdownItems(Auth::user()->hasPower('edit_data'), $species),
]);
}

/**
* Edits a design update request's features section.
*
Expand Down
74 changes: 50 additions & 24 deletions app/Models/Feature/Feature.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use App\Models\Rarity;
use App\Models\Species\Species;
use App\Models\Species\Subtype;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Facades\DB;

class Feature extends Model {
Expand Down Expand Up @@ -97,10 +98,10 @@ public function category() {
/**
* Scope a query to sort features in alphabetical order.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param bool $reverse
* @param Builder $query
* @param bool $reverse
*
* @return \Illuminate\Database\Eloquent\Builder
* @return Builder
*/
public function scopeSortAlphabetical($query, $reverse = false) {
return $query->orderBy('name', $reverse ? 'DESC' : 'ASC');
Expand All @@ -109,9 +110,9 @@ public function scopeSortAlphabetical($query, $reverse = false) {
/**
* Scope a query to sort features in category order.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param Builder $query
*
* @return \Illuminate\Database\Eloquent\Builder
* @return Builder
*/
public function scopeSortCategory($query) {
if (FeatureCategory::all()->count()) {
Expand All @@ -124,9 +125,9 @@ public function scopeSortCategory($query) {
/**
* Scope a query to sort features in species order.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param Builder $query
*
* @return \Illuminate\Database\Eloquent\Builder
* @return Builder
*/
public function scopeSortSpecies($query) {
$ids = Species::orderBy('sort', 'DESC')->pluck('id')->toArray();
Expand All @@ -137,9 +138,9 @@ public function scopeSortSpecies($query) {
/**
* Scope a query to sort features in subtype order.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param Builder $query
*
* @return \Illuminate\Database\Eloquent\Builder
* @return Builder
*/
public function scopeSortSubtype($query) {
$ids = Subtype::orderBy('sort', 'DESC')->pluck('id')->toArray();
Expand All @@ -150,10 +151,10 @@ public function scopeSortSubtype($query) {
/**
* Scope a query to sort features in rarity order.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param bool $reverse
* @param Builder $query
* @param bool $reverse
*
* @return \Illuminate\Database\Eloquent\Builder
* @return Builder
*/
public function scopeSortRarity($query, $reverse = false) {
$ids = Rarity::orderBy('sort', $reverse ? 'ASC' : 'DESC')->pluck('id')->toArray();
Expand All @@ -164,10 +165,10 @@ public function scopeSortRarity($query, $reverse = false) {
/**
* Scope a query to sort features by newest first.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param mixed $reverse
* @param Builder $query
* @param mixed $reverse
*
* @return \Illuminate\Database\Eloquent\Builder
* @return Builder
*/
public function scopeSortNewest($query, $reverse = false) {
return $query->orderBy('id', $reverse ? 'ASC' : 'DESC');
Expand All @@ -176,10 +177,10 @@ public function scopeSortNewest($query, $reverse = false) {
/**
* Scope a query to show only visible features.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param mixed|null $user
* @param Builder $query
* @param mixed|null $user
*
* @return \Illuminate\Database\Eloquent\Builder
* @return Builder
*/
public function scopeVisible($query, $user = null) {
if ($user && $user->hasPower('edit_data')) {
Expand Down Expand Up @@ -286,7 +287,7 @@ public function getAdminPowerAttribute() {

**********************************************************************************************/

public static function getDropdownItems($withHidden = 0) {
public static function getDropdownItems($withHidden = 0, $withSpecies = 0) {
$visibleOnly = 1;
if ($withHidden) {
$visibleOnly = 0;
Expand All @@ -295,10 +296,21 @@ public static function getDropdownItems($withHidden = 0) {
if (config('lorekeeper.extensions.organised_traits_dropdown.enable')) {
$sorted_feature_categories = collect(FeatureCategory::all()->where('is_visible', '>=', $visibleOnly)->sortBy('sort')->pluck('name')->toArray());

$grouped = self::where('is_visible', '>=', $visibleOnly)
->select('name', 'id', 'feature_category_id', 'rarity_id', 'species_id', 'subtype_id')->with(['category', 'rarity', 'species', 'subtype'])
->orderBy('name')->get()->keyBy('id')->groupBy('category.name', $preserveKeys = true)
->toArray();
if (config('show_exlusively_species_traits_in_dropdown') && $withSpecies) {
$grouped = self::where('is_visible', '>=', $visibleOnly)
->when($withSpecies, function (Builder $query, int $withSpecies) {
$query->where('species_id', '=', $withSpecies)
->orWhere('species_id', '=', null);
})
->select('name', 'id', 'feature_category_id', 'rarity_id', 'species_id', 'subtype_id')->with(['category', 'rarity', 'species', 'subtype'])
->orderBy('name')->get()->keyBy('id')->groupBy('category.name', $preserveKeys = true)
->toArray();
} else {
$grouped = self::where('is_visible', '>=', $visibleOnly)
->select('name', 'id', 'feature_category_id', 'rarity_id', 'species_id', 'subtype_id')->with(['category', 'rarity', 'species', 'subtype'])
->orderBy('name')->get()->keyBy('id')->groupBy('category.name', $preserveKeys = true)
->toArray();
}
if (isset($grouped[''])) {
if (!$sorted_feature_categories->contains('Miscellaneous')) {
$sorted_feature_categories->push('Miscellaneous');
Expand Down Expand Up @@ -353,7 +365,21 @@ public static function getDropdownItems($withHidden = 0) {

return $features_by_category;
} else {
return self::where('is_visible', '>=', $visibleOnly)->orderBy('name')->pluck('name', 'id')->toArray();
if (config('show_exlusively_species_traits_in_dropdown') && $withSpecies) {
return self::where('is_visible', '>=', $visibleOnly)
->when($withSpecies, function (Builder $query, int $withSpecies) {
$query->where('species_id', '=', $withSpecies)
->orWhere('species_id', '=', null);
})
->orderBy('name')
->pluck('name', 'id')
->toArray();
} else {
return self::where('is_visible', '>=', $visibleOnly)
->orderBy('name')
->pluck('name', 'id')
->toArray();
}
}
}
}
3 changes: 3 additions & 0 deletions config/lorekeeper/extensions.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,7 @@

// Unmerge Item Page and Item Entry - Speedy
'unmerge_item_page_and_entry' => 0, // If enabled, uses the html on world/item_page.blade.php instead of the include that links to world/_item_entry.blade.php

// Show Species-only traits in dropdown - Speedy
'show_exlusively_species_traits_in_dropdown' => 0, // If enabled, will only show traits from the associated species as well as traits that aren't species-limited in the dropdown menus.
];
17 changes: 16 additions & 1 deletion resources/views/character/admin/_edit_features_modal.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
</div>
@endforeach
</div>
<div class="feature-row hide mb-2">
<div class="feature-row hide mb-2" id="new-feature">
{!! Form::select('feature_id[]', $features, null, ['class' => 'form-control mr-2 feature-select', 'placeholder' => 'Select Trait']) !!}
{!! Form::text('feature_data[]', null, ['class' => 'form-control mr-2', 'placeholder' => 'Extra Info (Optional)']) !!}
<a href="#" class="remove-feature btn btn-danger mb-2">×</a>
Expand Down Expand Up @@ -116,6 +116,7 @@ function featureSelectedRender(item, escape) {

$("#species").change(function() {
refreshSubtype();
refreshTrait();
});

function refreshSubtype() {
Expand All @@ -135,6 +136,20 @@ function refreshSubtype() {
});
};


function refreshTrait() {
var species = $('#species').val();
$.ajax({
type: "GET",
url: "{{ url('designs/traits/feature') }}?species=" + species,
dataType: "text"
}).done(function(res) {
$("#new-feature").html(res);
}).fail(function(jqXHR, textStatus, errorThrown) {
alert("AJAX call failed: " + textStatus + ", " + errorThrown);
});
};

$("#subtype").selectize({
maxItems: {{ config('lorekeeper.extensions.multiple_subtype_limit') }},
});
Expand Down
3 changes: 3 additions & 0 deletions resources/views/character/design/_features_trait.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{!! Form::select('feature_id[]', $features, null, ['class' => 'form-control mr-2 feature-select', 'placeholder' => 'Select Trait']) !!}
{!! Form::text('feature_data[]', null, ['class' => 'form-control mr-2', 'placeholder' => 'Extra Info (Optional)']) !!}
<a href="#" class="remove-feature btn btn-danger mb-2">×</a>
20 changes: 19 additions & 1 deletion resources/views/character/design/features.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
@endforeach
@endif
</div>
<div class="feature-row hide mb-2">
<div class="feature-row hide mb-2" id="new-feature">
{!! Form::select('feature_id[]', $features, null, ['class' => 'form-control mr-2 feature-select', 'placeholder' => 'Select Trait']) !!}
{!! Form::text('feature_data[]', null, ['class' => 'form-control mr-2', 'placeholder' => 'Extra Info (Optional)']) !!}
<a href="#" class="remove-feature btn btn-danger mb-2">×</a>
Expand Down Expand Up @@ -144,6 +144,11 @@

<script>
$("#species").change(function() {
refreshSubtype();
refreshTrait();
});

function refreshSubtype() {
var species = $('#species').val();
var id = '<?php echo $request->id; ?>';
$.ajax({
Expand All @@ -158,6 +163,19 @@
}).fail(function(jqXHR, textStatus, errorThrown) {
alert("AJAX call failed: " + textStatus + ", " + errorThrown);
});
};

function refreshTrait() {
var species = $('#species').val();
$.ajax({
type: "GET",
url: "{{ url('designs/traits/feature') }}?species=" + species,
dataType: "text"
}).done(function(res) {
$("#new-feature").html(res);
}).fail(function(jqXHR, textStatus, errorThrown) {
alert("AJAX call failed: " + textStatus + ", " + errorThrown);
});
});

$("#subtype").selectize({
Expand Down
1 change: 1 addition & 0 deletions resources/views/widgets/_image_upload_js.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ function addFeatureRow() {
var $clone = $('.feature-row').clone();
$('#featureList').append($clone);
$clone.removeClass('hide feature-row');
$clone.removeAttr('id');
$clone.addClass('d-flex');
$clone.find('.remove-feature').on('click', function(e) {
e.preventDefault();
Expand Down
1 change: 1 addition & 0 deletions routes/lorekeeper/members.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@
Route::get('{id}/traits', 'DesignController@getFeatures');
Route::post('{id}/traits', 'DesignController@postFeatures');
Route::get('traits/subtype', 'DesignController@getFeaturesSubtype');
Route::get('traits/feature', 'DesignController@getFeaturesTrait');

Route::get('{id}/confirm', 'DesignController@getConfirm');
Route::post('{id}/submit', 'DesignController@postSubmit');
Expand Down