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

Small updates to admin team page #29

Merged
merged 6 commits into from
Aug 19, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,27 @@ public function store(): JsonResponse

try {

$model = new TeamMerchantTeam();

foreach ($validationArray as $key => $validationRule) {
$value = $this->request->get($key);
if ((isset($value))) {
$model->$key = $value;
$model = TeamMerchantTeam::where('team_id', $this->request->get('team_id'))
->where('merchant_team_id', $this->request->get('merchant_team_id'))
->first();

if (!$model) {
$model = new TeamMerchantTeam();

foreach ($validationArray as $key => $validationRule) {
$value = $this->request->get($key);
if ((isset($value))) {
$model->$key = $value;
}
}
}

$model->save();
$model->save();

}

$this->message = ApiResponse::RESPONSE_SAVED->value;
$this->data = $model;

$this->data = $model;

}
catch (Exception $e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,27 @@ public function store(): JsonResponse

try {

$model = new TeamServiceTeam();

foreach ($validationArray as $key => $validationRule) {
$value = $this->request->get($key);
if ((isset($value))) {
$model->$key = $value;
$model = TeamServiceTeam::where('team_id', $this->request->get('team_id'))
->where('service_team_id', $this->request->get('service_team_id'))
->first();

if (!$model) {
$model = new TeamServiceTeam();

foreach ($validationArray as $key => $validationRule) {
$value = $this->request->get($key);
if ((isset($value))) {
$model->$key = $value;
}
}
}

$model->save();
$model->save();

}

$this->message = ApiResponse::RESPONSE_SAVED->value;
$this->data = $model;

$this->data = $model;

}
catch (Exception $e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,15 @@ class ApiAdminTeamsController extends Controller
/**
* Set the related data the GET request is allowed to ask for
*/
public array $availableRelations = [];
public array $availableRelations = [
'teamsThisTeamIsMerchantFor',
'teamsThisTeamIsServiceFor',
];

public static array $searchableFields = [
'id',
'name',

];

/**
Expand Down
20 changes: 20 additions & 0 deletions app/Models/Team.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,24 @@ public function auditItems(): MorphMany
{
return $this->morphMany(AuditItem::class, 'auditable');
}

public function teamMerchantTeams(): HasMany
{
return $this->hasMany(TeamMerchantTeam::class, 'team_id', 'id');
}

public function teamsThisTeamIsMerchantFor(): HasMany
{
return $this->hasMany(TeamMerchantTeam::class, 'merchant_team_id', 'id');
}

public function teamServiceTeams(): HasMany
{
return $this->hasMany(TeamServiceTeam::class, 'team_id', 'id');
}

public function teamsThisTeamIsServiceFor(): HasMany
{
return $this->hasMany(TeamServiceTeam::class, 'service_team_id', 'id');
}
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
<script setup>
import {onMounted, ref} from "vue";
import {ref} from "vue";
import TextInput from "@/Components/TextInput.vue";
import InputLabel from "@/Components/InputLabel.vue";
import AdminTeamDetailsComponent from "@/Components/Admin/AdminTeamDetailsComponent.vue";
import AdminTeamCreateComponent from "@/Components/Admin/AdminTeamCreateComponent.vue";

const $props = defineProps({
excludeTeams: {
required: false,
default: {}
},

teamId: {
required: false,
default: null
}
})

const creatingANewTeam = ref(false)
const excludeTeamIdsArray = ref([])
const searchStr = ref('')
const teams = ref({})

Expand All @@ -26,35 +22,17 @@ const emit = defineEmits([
]
);

onMounted(() => {
createExcludeTeamIdsArray()
})

function createExcludeTeamIdsArray() {
if ($props.excludeTeams.data && $props.excludeTeams.data.length > 0) {
$props.excludeTeams.data.forEach((team) => {
if (team.service_team_id) {
excludeTeamIdsArray.value.push(team.service_team_id)
}
if (team.merchant_team_id) {
excludeTeamIdsArray.value.push(team.merchant_team_id)
}
})
}

if ($props.teamId) {
excludeTeamIdsArray.value.push($props.teamId)
}
}

function searchTeam() {
axios.get('/admin/teams?where[]=name,like,*' + searchStr.value + '*&limit=100').then(response => {
teams.value = response.data.data
axios.get('/admin/teams?where[]=name,like,*' + searchStr.value + '*&limit=100&relations=teamsThisTeamIsMerchantFor').then(response => {
teams.value = response.data.data;

}).catch(error => {
console.log(error)
})
});
}



function startCreatingNewTeam() {
creatingANewTeam.value = true
teams.value = {}
Expand All @@ -70,6 +48,12 @@ function teamSelected(team) {
teams.value = {}
}

function myTeamIsATeamMerchant(anotherTeam){
return anotherTeam.teams_this_team_is_merchant_for.find(subTeam => {
return subTeam.team_id === $props.teamId;
});
}

</script>

<template>
Expand All @@ -91,10 +75,9 @@ function teamSelected(team) {

<div v-if="searchStr.length > 0 && teams.total > 0" class="mt-4">
<div v-for="team in teams.data" class="border-b py-1">
<button @click="teamSelected(team)" class="cursor-pointer flex justify-start items-end"
:class="{'text-gray-500 cursor-not-allowed': excludeTeamIdsArray.includes(team.id)}"
:disabled="excludeTeamIdsArray.includes(team.id)">
<button @click="teamSelected(team)" class="flex justify-start items-end">
<AdminTeamDetailsComponent :team="team"/>
<span v-if="myTeamIsATeamMerchant(team)" class="text-red-500 text-xs italic pl-2">***Already added</span>
</button>
</div>
<div class="text-red-500 text-sm mt-4 cursor-pointer hover:underline" @click="startCreatingNewTeam()">
Expand All @@ -108,4 +91,5 @@ function teamSelected(team) {
</div>
</div>
</div>

</template>
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
<script setup>
import {onMounted, ref} from "vue";
import {Link} from '@inertiajs/vue3';
import AdminTeamDetailsComponent from "@/Components/Admin/AdminTeamDetailsComponent.vue";
import PrimaryButton from "@/Components/PrimaryButton.vue";
import Swal from "sweetalert2";
import AdminTeamSelectComponent from "@/Components/Admin/AdminTeamSelectComponent.vue";
import PaginatorComponent from "@/Components/Admin/PaginatorComponent.vue";
import AdminTeamMerchantTeamSelectComponent
from "@/Components/Admin/TeamMerchantTeams/AdminTeamMerchantTeamSelectComponent.vue";

const $props = defineProps({
teamId: {
Expand Down Expand Up @@ -31,16 +34,22 @@ function addNewMerchant() {
addingNewMerchant.value = true
}

function getMerchants() {
axios.get('/admin/team-merchant-teams?cached=false&where[]=team_id,' + $props.teamId + '&relations=merchantTeam').then(response => {
function cancelAddingNewMerchant() {
addingNewMerchant.value = false
creatingNewTeamMerchant.value = false
teamAddingAsMerchant.value = {}
}

function getMerchants(page = 1) {
axios.get('/admin/team-merchant-teams?cached=false&where[]=team_id,' + $props.teamId + '&page=' + page + '&relations=merchantTeam').then(response => {
merchants.value = response.data.data
}).catch(error => {
console.log(error)
})
}

function getMerchantTeams() {
axios.get('/admin/team-merchant-teams?cached=false&where[]=merchant_team_id,' + $props.teamId + '&relations=team').then(response => {
function getMerchantTeams(page = 1) {
axios.get('/admin/team-merchant-teams?cached=false&where[]=merchant_team_id,' + $props.teamId + '&page=' + page + '&relations=team').then(response => {
merchantTeams.value = response.data.data
}).catch(error => {
console.log(error)
Expand Down Expand Up @@ -79,22 +88,28 @@ function teamSelected(team) {

<template>
<div class="flex justify-end">
<PrimaryButton @click="addNewMerchant()" class="ms-4">
Add Merchant Team
</PrimaryButton>
<div v-if="!addingNewMerchant && !creatingNewTeamMerchant">
<PrimaryButton @click="addNewMerchant()" class="ms-4">
Add Merchant Team
</PrimaryButton>
</div>
<div v-else>
<PrimaryButton @click="cancelAddingNewMerchant()" class="ms-4">
Cancel
</PrimaryButton>
</div>
</div>

<div v-if="addingNewMerchant">
<div class="py-2">Select merchant team...</div>
<AdminTeamSelectComponent :excludeTeams="merchants" :teamId="teamId" @teamSelected="teamSelected"/>
<AdminTeamMerchantTeamSelectComponent :teamId="teamId" @teamSelected="teamSelected"></AdminTeamMerchantTeamSelectComponent>
</div>

<div v-else-if="creatingNewTeamMerchant">
<div class="py-2">Add <span class="font-bold">{{ teamAddingAsMerchant.name }}</span> as merchant team?</div>
<PrimaryButton @click="submitTeamMerchant()" class="">
Add
</PrimaryButton>

</div>

<div v-else>
Expand All @@ -109,7 +124,16 @@ function teamSelected(team) {
</div>

<div v-for="merchant in merchants.data" class="border-b py-1">
<AdminTeamDetailsComponent :team="merchant.merchant_team"/>
<Link :href="route('admin.team', merchant.merchant_team_id)">
<AdminTeamDetailsComponent :team="merchant.merchant_team"/>
</Link>
</div>
<div class="flex justify-end items-center mt-4">
<div class="w-full lg:w-1/3">
<PaginatorComponent
@setDataPage="getMerchants"
:pagination-data="merchants"></PaginatorComponent>
</div>
</div>
</div>

Expand All @@ -124,7 +148,16 @@ function teamSelected(team) {
</div>

<div v-for="merchantTeam in merchantTeams.data" class="border-b py-1">
<AdminTeamDetailsComponent :team="merchantTeam.team"/>
<Link :href="route('admin.team', merchantTeam.team_id)">
<AdminTeamDetailsComponent :team="merchantTeam.team"/>
</Link>
</div>
<div class="flex justify-end items-center mt-4">
<div class="w-full lg:w-1/3">
<PaginatorComponent
@setDataPage="getMerchantTeams"
:pagination-data="merchantTeams"></PaginatorComponent>
</div>
</div>
</div>

Expand Down
Loading
Loading