Skip to content
Snippets Groups Projects
List.vue 5.46 KiB
Newer Older
Pierre-Jean CHANCELLIER's avatar
Pierre-Jean CHANCELLIER committed
	<div class="certifList" v-if="certifs.length > 0">
Pierre-Jean CHANCELLIER's avatar
Pierre-Jean CHANCELLIER committed
		<button
			:title="
				isOpen ? $t('certification.masquer') : $t('certification.afficher')
			"
			@click="isOpen = !isOpen"
			class="btn w-100 m-auto d-block rounded-0"
			:class="btnClass"
			type="button"
			data-bs-toggle="collapse"
			:data-bs-target="'#' + collapseId"
			aria-expanded="false"
			:aria-controls="collapseId">
			<span v-if="!isOpen">
				<solid-eye-icon class="icon" aria-hidden="true" />
			</span>
			<span v-else>
				<solid-eye-off-icon class="icon" aria-hidden="true" />
			</span>
			<h4 class="d-inline align-middle">
				{{ title }}&nbsp;&nbsp;
				<span class="badge rounded-pill bg-white opacity-75 text-dark">{{
					certifs.length
				}}</span>
			</h4>
		</button>
		<div
			:id="collapseId"
			class="table-responsive collapse p-3"
			:class="collapseClass">
			<BtnSearch
				@erase="search = ''"
				v-model="search"
				class="px-2"
				v-if="certifs.length > 5" />
			<table
				class="table table-striped table-hover table-fixed sortable border m-0">
				<thead class="thead-light">
					<tr>
						<th class="p-0">
Pierre-Jean CHANCELLIER's avatar
Pierre-Jean CHANCELLIER committed
							<BtnSort
								:title="$t('membre.title')"
								fieldName="uid"
								:tableName="collapseId"
Pierre-Jean CHANCELLIER's avatar
Pierre-Jean CHANCELLIER committed
								:currentSort="currentSort"
								:currentSortDir="currentSortDir" />
						</th>
						<th class="p-0 col-4">
Pierre-Jean CHANCELLIER's avatar
Pierre-Jean CHANCELLIER committed
							<BtnSort
								:title="$t('expire')"
								fieldName="expires_on"
								:tableName="collapseId"
Pierre-Jean CHANCELLIER's avatar
Pierre-Jean CHANCELLIER committed
								:currentSort="currentSort"
								:currentSortDir="currentSortDir" />
						</th>
					</tr>
				</thead>
				<tbody>
					<tr
						v-for="certif in certifsTriees"
						:key="certif.uid"
						tabindex="0"
						:title="$t('membre.voirinfos')"
						@click="
							$router.push(
								localePath({
Pierre-Jean CHANCELLIER's avatar
Pierre-Jean CHANCELLIER committed
									name: 'membres-profil',
Pierre-Jean CHANCELLIER's avatar
Pierre-Jean CHANCELLIER committed
									query: { hash: certif.hash }
								})
							)
						"
						@keyup.enter="
							$router.push(
								localePath({
Pierre-Jean CHANCELLIER's avatar
Pierre-Jean CHANCELLIER committed
									name: 'membres-profil',
Pierre-Jean CHANCELLIER's avatar
Pierre-Jean CHANCELLIER committed
									query: { hash: certif.hash }
								})
							)
						">
						<td class="py-1">
							<div class="d-flex">
								<span v-if="$favourites.list.includes(certif.uid)"
									>&nbsp;</span
								>
								<div class="text-truncate">{{ certif.uid }}</div>
								&nbsp;
								<BadgeDanger
									style="width: 1.2rem"
									:limitDate="certif.certsLimit"
									:memberStatus="certif.status" />
							</div>
							<BadgeStatus :membre="certif" />
							<BadgeQuality
								:quality="certif.quality.ratio"
								v-if="!['REVOKED', 'NEWCOMER'].includes(certif.status)" />
							<BadgeDispo
								:isDispo="certif.minDatePassed"
								:dateDispo="certif.minDate"
								:certifs="certif.sent_certifications"
								v-if="certif.status == 'MEMBER'" />
						</td>
						<td class="p-0 text-center col-4">
Pierre-Jean CHANCELLIER's avatar
Pierre-Jean CHANCELLIER committed
							<div class="d-inline-flex flex-column gap-1">
Pierre-Jean CHANCELLIER's avatar
Pierre-Jean CHANCELLIER committed
								<BadgeDate :date="certif.expires_on" />
								<span
									class="badge bg-secondary text-truncate d-block"
									v-if="certif.pending"
									>{{ $t("traitement") }}</span
								>
							</div>
						</td>
					</tr>
				</tbody>
			</table>
		</div>
</template>

<script>
export default {
	data() {
		return {
			currentSort: "expires_on",
Pierre-Jean CHANCELLIER's avatar
Pierre-Jean CHANCELLIER committed
			currentSortDir: "asc",
Pierre-Jean CHANCELLIER's avatar
Pierre-Jean CHANCELLIER committed
			isOpen: this.openDefault
Pierre-Jean CHANCELLIER's avatar
Pierre-Jean CHANCELLIER committed
		certifs: Array,
		certifStatus: String,
		collapseId: String,
		title: String,
		openDefault: {
			type: Boolean,
			default: false
		}
	},
	computed: {
		certifsFiltrees() {
			return this.certifs.filter((row, index) => {
				return (
					this.search == "" ||
					row.uid.toLowerCase().includes(this.search.toLowerCase())
				)
			})
		},
		certifsTriees() {
			return this.certifsFiltrees
Pierre-Jean CHANCELLIER's avatar
Pierre-Jean CHANCELLIER committed
				.map((el) => {
					el.status =
						this.$options.filters.dateStatus(el.limitDate) == "warning"
							? "RENEW"
							: el.status
					return el
				})
				.sort((a, b) => {
					let modifier = this.currentSortDir === "desc" ? -1 : 1
					if (this.currentSort == "expires_on") {
						if (a["expires_on"] < b["expires_on"]) return -1 * modifier
						if (a["expires_on"] > b["expires_on"]) return 1 * modifier
					} else {
						if (a["uid"].toLowerCase() < b["uid"].toLowerCase())
							return -1 * modifier
						if (a["uid"].toLowerCase() > b["uid"].toLowerCase())
							return 1 * modifier
					}
Pierre-Jean CHANCELLIER's avatar
Pierre-Jean CHANCELLIER committed
		},
		collapseClass() {
			if (this.collapseId.includes("entraitement")) return "bg-secondary"
			if (this.collapseId.includes("perimees")) return "bg-warning"
			if (this.collapseId == "sent-encours") return "bg-info"
			return {
				"bg-success": this.certifStatus == "success",
				"bg-warning": this.certifStatus == "warning",
				"bg-danger": this.certifStatus == "danger"
			}
		},
		btnClass() {
			if (this.collapseId.includes("entraitement")) return "btn-secondary"
			if (this.collapseId.includes("perimees")) return "btn-warning"
			if (this.collapseId == "sent-encours") return "btn-info"
			return {
				"btn-success": this.certifStatus == "success",
				"btn-warning": this.certifStatus == "warning",
				"btn-danger": this.certifStatus == "danger"
			}
		}
	},
	mounted() {
		if (this.openDefault && this.certifs.length > 0) {
			document.querySelector("#" + this.collapseId).classList.add("show")
	},
	watch: {
		certifs: {
			handler(n, o) {
				this.search = ""
			}
		}
Pierre-Jean CHANCELLIER's avatar
Pierre-Jean CHANCELLIER committed
<style lang="scss">
.certifList {
	.table-responsive tbody {
		max-height: 456px;
Pierre-Jean CHANCELLIER's avatar
Pierre-Jean CHANCELLIER committed
	}

	tbody tr {
Pierre-Jean CHANCELLIER's avatar
Pierre-Jean CHANCELLIER committed
		height: 80px;
	}

	@media (min-width: 576px) {
		button {
			font-size: 1.3rem;
		}

		tbody tr {
			height: initial;
		}
Pierre-Jean CHANCELLIER's avatar
Pierre-Jean CHANCELLIER committed
	}