Commit c78151bc by Vladislav
2 parents 58833cb1 4125404e
......@@ -52,8 +52,7 @@ class FirstLoadCampaigns extends Command
$factory = APIRequest::getInstance(API::YANDEX);
$factory->setToken($token);
$factory->getRequest('change', 'CheckDictionaries')
->call();
$factory->getRequest('change', 'CheckDictionaries')->call();
$factory->getRequest('campaigns', 'get')->call();
return 0;
......
......@@ -35,7 +35,7 @@ class TokensController extends Controller
}
function edit(Tokens $token){
$mainToken = Tokens::where('type', Tokens::MAIN)->get();
$mainToken = Tokens::where('type', Tokens::MAIN)->get()->first();
return Inertia::render('Tokens/Edit', [
'token' => [
'id' => $token->id,
......@@ -43,16 +43,18 @@ class TokensController extends Controller
'api' => $token->api,
'token' => $token->token,
'type' => $token->type,
'main' => $token->type==Tokens::MAIN,
'campaigns' => (
$token->type === Tokens::MAIN
? $token->campaignsForManaged
: []
),
'cities' => ($token->type==Tokens::GOAL?$token->cities:null),
'cities' => ($token->type==Tokens::GOAL?$token->cities:[]),
],
'cities' => Dictionary::where('type', Dictionary::CITY)->get(),
'campaigns' => $token->campaigns,
'types' => $mainToken->count() && $token->type!=Tokens::MAIN
'main_token_campaigns' => $mainToken->campaignsForManaged,
'types' => $mainToken && $token->type!=Tokens::MAIN
? [Tokens::GOAL=> 'Целевой аккаунт'] :
[Tokens::MAIN => 'Основной аккаунт', Tokens::GOAL=> 'Целевой аккаунт'],
]);
......@@ -125,6 +127,9 @@ class TokensController extends Controller
public function addCity(Tokens $token)
{
$token;
$city = Dictionary::findOrFail(Request::input('city'));
$token->cities()->save($city);
return Redirect::route('token.edit', $token->id)->with('success', 'City added.');
}
}
......@@ -24,14 +24,45 @@
<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>
<th class="px-6 pt-6 pb-4" colspan="2">Name</th>
<th class="px-6 pt-6 pb-4">Обновлять?</th>
<th class="px-6 pt-6 pb-4"></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">
<template v-for="city in cities" >
<tr :key="city.id" class="hover:bg-gray-100 focus-within:bg-gray-100">
<td colspan="2" class="border-t">
<span class="px-6 py-4 flex items-center focus:text-indigo-500"> {{ city.name }} </span>
</td>
<td class="border-t">
<input :checked="city.update"
@change=""
type="checkbox"
>
</td>
<td>
<inertia-link class="px-4 flex items-center" :href="route('token.city.delete', city.id)" tabindex="-1">
<icon name="trash" class="block w-6 h-6 fill-gray-400" />
</inertia-link>
</td>
</tr>
<tr>
<th class="px-6 pt-6 pb-4" ></th>
<th class="px-6 pt-6 pb-4">Кампания</th>
<th class="px-6 pt-6 pb-4">Синхронизировать?</th>
<th></th>
</tr>
<tr v-for="camp in main_token_campaigns">
<td class="border-t"></td>
<td class="border-t"><span class="px-6 py-4 flex items-center focus:text-indigo-500"> {{ camp.name }} </span></td>
<td class="border-t">
<input :checked="camp.update"
@change=""
type="checkbox"
>
</td>
<td></td>
</tr>
</template>
<tr v-if="cities.length === 0">
<td class="border-t px-6 py-4" colspan="4">No City found.</td>
</tr>
......@@ -43,11 +74,13 @@
<script>
import SelectInput from "../../Shared/SelectInput";
import Icon from "../../Shared/Icon";
export default {
components: {SelectInput},
components: {Icon, SelectInput},
props: {
cities: Array,
all_cities: Array,
main_token_campaigns: Array,
},
data() {
return {
......
......@@ -36,7 +36,7 @@
</div>
</form>
</div>
<div v-if="campaigns.length || token.campaigns.length">
<div v-if="campaigns.length && token.main">
<h2 class="mt-12 font-bold text-2xl">Campaigns</h2>
<div class="mt-4 flex flex-wrap">
<form v-if="campaigns.length" @submit.prevent="campaignAdd" class="flex flex-wrap">
......@@ -93,7 +93,12 @@
</div>
</div>
<city-settings :cities="state.cities" :all_cities="cities" v-on:add="addCity"></city-settings>
<city-settings v-if="!token.main"
:cities="state.cities"
:all_cities="cities"
:main_token_campaigns="main_token_campaigns"
v-on:add="addCity"
></city-settings>
</div>
</template>
......@@ -124,6 +129,7 @@ export default {
token: Object,
types: Object,
cities: Array,
main_token_campaigns: Array,
},
remember: 'form',
data() {
......@@ -157,7 +163,7 @@ export default {
this.state.cities.push(found)
this.$inertia.form({
city: id
}).post(this.route('token.city.add'), this.token.id)
}).post(this.route('token.city.add', this.token.id))
},
tokenUpdate() {
this.form.post(this.route('token.update', this.token.id))
......
......@@ -178,6 +178,9 @@ Route::post('token/campaigns/enabled/{token}/{campaign_id}/{enabled}', [TokensCo
Route::post('token/city/add/{token}', [TokensController::class, 'addCity'])
->name('token.city.add')
->middleware('auth');
Route::post('token/city/delete/{city}', [TokensController::class, 'removeCity'])
->name('token.city.delete')
->middleware('auth');
Route::delete('token/delete/{token}', [TokensController::class, 'destroy'])
->name('token.destroy')
->middleware('auth');
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!