Commit f0a4dd0f by Евгений

Улучшение #19461

Страница настройки целевых аккаунтов.
1 parent 3f4c855c
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Models\Campaigns; use App\Models\Campaigns;
use App\Models\Dictionary;
use App\Models\Tokens; use App\Models\Tokens;
use App\Service\API\API; use App\Service\API\API;
use App\Service\Requests\APIRequest; use App\Service\Requests\APIRequest;
...@@ -45,8 +46,9 @@ class TokensController extends Controller ...@@ -45,8 +46,9 @@ class TokensController extends Controller
? $token->campaignsForManaged ? $token->campaignsForManaged
: [] : []
), ),
'cities' => ($token->type==Tokens::GOAL?[]:null), 'cities' => ($token->type==Tokens::GOAL?$token->cities:null),
], ],
'cities' => Dictionary::where('type', Dictionary::CITY)->get(),
'campaigns' => $token->campaigns, 'campaigns' => $token->campaigns,
'types' => $mainToken->count() && $token->type!=Tokens::MAIN 'types' => $mainToken->count() && $token->type!=Tokens::MAIN
? [Tokens::GOAL=> 'Целевой аккаунт'] : ? [Tokens::GOAL=> 'Целевой аккаунт'] :
...@@ -99,4 +101,9 @@ class TokensController extends Controller ...@@ -99,4 +101,9 @@ class TokensController extends Controller
return Redirect::route('tokens')->with('success', 'Token added.'); return Redirect::route('tokens')->with('success', 'Token added.');
} }
public function addCity(Tokens $token)
{
$token
}
} }
...@@ -4,5 +4,6 @@ namespace App\Models; ...@@ -4,5 +4,6 @@ namespace App\Models;
class Dictionary extends Model class Dictionary extends Model
{ {
CONST CITY = 'city';
} }
...@@ -33,6 +33,10 @@ class Tokens extends Model ...@@ -33,6 +33,10 @@ class Tokens extends Model
return $this->hasMany(Campaigns::class, 'token', 'id')->orderBy('updated_at', 'DESC'); return $this->hasMany(Campaigns::class, 'token', 'id')->orderBy('updated_at', 'DESC');
} }
public function cities(){
return $this->hasMany(Dictionary::class, 'token', 'id');
}
public function campaignsForManaged() public function campaignsForManaged()
{ {
return $this->campaigns()->forManaged(); return $this->campaigns()->forManaged();
......
...@@ -19,6 +19,8 @@ class CreateDictionariesTable extends Migration ...@@ -19,6 +19,8 @@ class CreateDictionariesTable extends Migration
$table->bigInteger('parent_id')->nullable(); $table->bigInteger('parent_id')->nullable();
$table->string('name', 255); $table->string('name', 255);
$table->string('type', 255); $table->string('type', 255);
$table->bigInteger('token')->nullable();
$table->boolean('update')->default(1);
$table->timestamps(); $table->timestamps();
}); });
} }
......
<template>
<div>
<h2 class="mt-12 font-bold text-2xl">Cities</h2>
<div class="mt-4 flex flex-wrap">
<div v-if="all_cities" class="flex flex-wrap">
<select-input v-model="city" class="px-6">
<option v-for="city in all_cities" :value="city.id">
{{ city.name }}
</option>
</select-input>
<button class="btn-indigo hover:underline"
tabindex="-1"
type="button"
@click="cityAdd"
>
Add
</button>
</div>
</div>
<div class="mt-6 bg-white rounded shadow">
<table class="w-full whitespace-nowrap">
<tr class="text-left font-bold">
<th class="px-6 pt-6 pb-4">Name</th>
</tr>
<tr v-for="city in cities" :key="city.id"
class="hover:bg-gray-100 focus-within:bg-gray-100">
<td class="border-t">
<span class="px-6 py-4 flex items-center focus:text-indigo-500"> {{ city.name }} </span>
</td>
</tr>
<tr v-if="cities.length === 0">
<td class="border-t px-6 py-4" colspan="4">No City found.</td>
</tr>
</table>
</div>
</div>
</template>
<script>
import SelectInput from "../../Shared/SelectInput";
export default {
components: {SelectInput},
props: {
cities: Array,
all_cities: Array,
},
data() {
return {
city: false
}
},
watch: {
},
mounted() {
},
methods: {
cityAdd(){
this.$emit('add', this.city)
}
}
}
</script>
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
</div> </div>
</form> </form>
</div> </div>
<div v-if="state.campaigns.length || state.token_campaigns.length"> <div v-if="campaigns.length">
<h2 class="mt-12 font-bold text-2xl">Campaigns</h2> <h2 class="mt-12 font-bold text-2xl">Campaigns</h2>
<div class="mt-4 flex flex-wrap"> <div class="mt-4 flex flex-wrap">
<div v-if="state.campaigns.length" class="flex flex-wrap"> <div v-if="state.campaigns.length" class="flex flex-wrap">
...@@ -94,26 +94,7 @@ ...@@ -94,26 +94,7 @@
</div> </div>
</div> </div>
<div v-if="token.cities"> <city-settings :cities="state.cities" :all_cities="cities" v-on:add="addCity"></city-settings>
<h2 class="mt-12 font-bold text-2xl">Cities</h2>
<div class="mt-6 bg-white rounded shadow overflow-x-auto">
<table class="w-full whitespace-nowrap">
<tr class="text-left font-bold">
<th class="px-6 pt-6 pb-4">Name</th>
</tr>
<tr v-for="city in token.cities" :key="city.id"
class="hover:bg-gray-100 focus-within:bg-gray-100">
<td class="border-t">
{{ city.name }}
</td>
</tr>
<tr v-if="token.cities.length === 0">
<td class="border-t px-6 py-4" colspan="4">No City found.</td>
</tr>
</table>
</div>
</div>
</div> </div>
</template> </template>
...@@ -124,12 +105,14 @@ import TextInput from '@/Shared/TextInput' ...@@ -124,12 +105,14 @@ import TextInput from '@/Shared/TextInput'
import SelectInput from '@/Shared/SelectInput' import SelectInput from '@/Shared/SelectInput'
import LoadingButton from '@/Shared/LoadingButton' import LoadingButton from '@/Shared/LoadingButton'
import TrashedMessage from '@/Shared/TrashedMessage' import TrashedMessage from '@/Shared/TrashedMessage'
import CitySettings from "./CitySettings";
export default { export default {
metaInfo() { metaInfo() {
return {title: this.form.login} return {title: this.form.login}
}, },
components: { components: {
CitySettings,
Icon, Icon,
LoadingButton, LoadingButton,
SelectInput, SelectInput,
...@@ -141,6 +124,7 @@ export default { ...@@ -141,6 +124,7 @@ export default {
campaigns: Array, campaigns: Array,
token: Object, token: Object,
types: Object, types: Object,
cities: Array,
}, },
remember: 'form', remember: 'form',
data() { data() {
...@@ -154,6 +138,8 @@ export default { ...@@ -154,6 +138,8 @@ export default {
}), }),
campaigns_form: this.$inertia.form(), campaigns_form: this.$inertia.form(),
state: { state: {
all_cities: this.cities,
cities: this.token.cities,
campaign_id: null, campaign_id: null,
campaigns: this.filterCampaigns(this.token.campaigns), campaigns: this.filterCampaigns(this.token.campaigns),
token_campaigns: this.token.campaigns, token_campaigns: this.token.campaigns,
...@@ -161,6 +147,19 @@ export default { ...@@ -161,6 +147,19 @@ export default {
} }
}, },
methods: { methods: {
addCity(id) {
let found;
this.state.all_cities = this.state.all_cities.filter((city)=>{
if (city.id==id){
found = city
}
return city.id!=id
})
this.state.cities.push(found)
this.$inertia.form({
city: id
}).post(this.route('token.city.add'), this.token.id)
},
tokenUpdate() { tokenUpdate() {
this.form.post(this.route('token.update', this.token.id)) this.form.post(this.route('token.update', this.token.id))
}, },
......
...@@ -172,6 +172,9 @@ Route::post('token/edit/{token}', [TokensController::class, 'update']) ...@@ -172,6 +172,9 @@ Route::post('token/edit/{token}', [TokensController::class, 'update'])
Route::post('token/campaigns/edit/{token}', [TokensController::class, 'updateCampaigns']) Route::post('token/campaigns/edit/{token}', [TokensController::class, 'updateCampaigns'])
->name('token.campaigns.update') ->name('token.campaigns.update')
->middleware('auth'); ->middleware('auth');
Route::post('token/city/add/{token}', [TokensController::class, 'addCity'])
->name('token.city.add')
->middleware('auth');
Route::delete('token/delete/{token}', [TokensController::class, 'destroy']) Route::delete('token/delete/{token}', [TokensController::class, 'destroy'])
->name('token.destroy') ->name('token.destroy')
->middleware('auth'); ->middleware('auth');
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!