media_player_client/src/components/PlanTree.vue

276 lines
8.8 KiB
Vue
Raw Normal View History

2021-08-25 17:30:02 +08:00
<template>
<div>
<q-scroll-area
:style="{ height: content_height + 'px' }"
style="width: 20vw"
>
<q-tree ref="tree" :nodes="tree_nodes" node-key="uuid" labelKey="name">
<template v-slot:default-header="prop">
<q-item
class="full-width"
clickable
2022-06-14 17:58:27 +08:00
:disable="!$store.state.power_state"
@dblclick="
(evt) => !prop.node.is_group && runPlan(prop.node.item_data)
"
>
<q-item-section avatar>
<q-icon
:name="
prop.node.is_group
? 'img:source_icon/group.png'
2022-03-30 14:52:20 +08:00
: 'img:new_icon/plan_icon.png'
2021-08-25 17:30:02 +08:00
"
color="orange"
size="28px"
class="q-mr-sm"
/>
</q-item-section>
<q-item-section>
<div class="text-weight-bold text-primary">
{{ prop.node.name }}
</div>
</q-item-section>
2022-06-14 17:58:27 +08:00
<q-popup-proxy :context-menu="$store.state.power_state">
<q-list>
<q-item
v-if="
prop.node.name == $t('plan') ||
(prop.node.is_group && prop.node.item_data)
"
clickable
v-close-popup
v-ripple
@click="
$refs.plan_dialog.showDialog({
2021-08-25 17:30:02 +08:00
type: 1,
data: { uuid: prop.node.uuid },
2021-08-25 17:30:02 +08:00
})
"
>
<q-item-section avatar><q-icon name="add" /></q-item-section>
<q-item-section>{{ $t("add plan item") }}</q-item-section>
</q-item>
<q-item
clickable
v-close-popup
v-if="
prop.node.name == $t('plan') ||
(prop.node.is_group && prop.node.item_data)
"
v-ripple
@click="
() =>
$refs.group_dialog.showDialog({
type: 1,
data: prop.node,
})
"
>
<q-item-section avatar
><q-icon name="create_new_folder"
/></q-item-section>
<q-item-section>{{ $t("add group") }}</q-item-section>
</q-item>
<q-item
clickable
v-ripple
v-close-popup
v-if="
prop.node.item_data &&
power_on_plan != prop.node.item_data.uuid
"
@click="
(evt) => setPowerOnPlan(evt, prop.node.item_data.uuid)
"
>
<q-item-section avatar
><q-icon name="timer"
/></q-item-section>
<q-item-section>{{
$t("set power on start")
}}</q-item-section>
</q-item>
<q-item
clickable
v-ripple
v-close-popup
v-if="
prop.node.item_data &&
power_on_plan == prop.node.item_data.uuid
"
@click="
(evt) => unsetPowerOnPlan(evt, prop.node.item_data.uuid)
"
>
<q-item-section avatar
><q-icon name="timer_off"
/></q-item-section>
<q-item-section>{{
$t("unset power on start")
}}</q-item-section>
</q-item>
<q-item
clickable
v-ripple
v-close-popup
v-if="prop.node.item_data"
@click="
() =>
(prop.node.is_group
? $refs.group_dialog
: $refs.plan_dialog
).showDialog({
type: 2,
data: prop.node,
})
"
>
<q-item-section avatar><q-icon name="edit" /></q-item-section>
<q-item-section>{{ $t("edit") }}</q-item-section>
</q-item>
2021-08-25 17:30:02 +08:00
<q-item
clickable
v-ripple
v-close-popup
v-if="prop.node.item_data"
@click="
(evt) => deleteItem(evt, prop.node.is_group, prop.node.uuid)
"
>
<q-item-section avatar
><q-icon color="red" name="delete"
/></q-item-section>
<q-item-section>{{ $t("delete") }} &nbsp;</q-item-section>
</q-item>
</q-list>
</q-popup-proxy>
</q-item>
</template>
</q-tree>
</q-scroll-area>
2021-08-25 17:30:02 +08:00
</div>
<plan-group-dialog ref="group_dialog" />
<plan-dialog ref="plan_dialog" />
</template>
<script lang="ts">
import { defineComponent, computed, onMounted, ref, nextTick } from "vue";
import { useStore } from "src/store";
import PlanGroupDialog from "src/components/PlanGroupDialog.vue";
import PlanDialog from "src/components/PlanDialog.vue";
import { Common } from "src/common/Common";
import GlobalData from "src/common/GlobalData";
import { useQuasar } from "quasar";
import { useI18n } from "vue-i18n";
import EventBus, { EventNamesDefine } from "src/common/EventBus";
import { Protocol } from "src/entities/WSProtocol";
import { PlanEntity } from "src/entities/PlanEntity";
import { NotifyMessage } from "src/common/ClientConnection";
export default defineComponent({
name: "ComponentPlanTree",
2021-08-25 17:30:02 +08:00
components: { PlanGroupDialog, PlanDialog },
setup() {
const $store = useStore();
const $q = useQuasar();
const $t = useI18n();
const tree_nodes = computed({
get: () => $store.state.plan_tree,
set: (val) => {},
});
const power_on_plan = computed({
get: () => $store.state.power_on_plan,
set: (val) => {},
});
const content_height = ref(0);
const refresh_content_height = () => {
content_height.value = window.innerHeight - 135;
};
refresh_content_height();
EventBus.getInstance().on(EventNamesDefine.WindowResize, () => {
refresh_content_height();
});
2021-08-25 17:30:02 +08:00
const tree: any | null = ref(null);
onMounted(async () => {
2022-03-03 16:36:47 +08:00
while (!tree.value?.nodes?.length) {
2021-08-25 17:30:02 +08:00
await Common.waitFor(100);
}
tree.value?.setExpanded("", true);
});
return {
tree,
tree_nodes,
content_height,
power_on_plan,
2021-08-25 17:30:02 +08:00
loga(a: any) {
console.log(a);
},
async deleteItem(
evt: PointerEvent | null,
is_group: boolean,
uuid: string
) {
let success = false;
if (is_group) {
let response = await GlobalData.getInstance()
.getCurrentClient()
?.deletePlanGroup(uuid);
if (response) {
success = response.success;
}
} else {
let response = await GlobalData.getInstance()
.getCurrentClient()
?.deletePlan(uuid);
if (response) {
success = response.success;
}
}
$q.notify({
color: success ? "positive" : "negative",
icon: success ? "done" : "warning",
message:
$t.t("delete") + (success ? $t.t("success") : $t.t("fail")) + "!",
position: "top",
2021-12-22 11:25:04 +08:00
timeout: 1500,
2021-08-25 17:30:02 +08:00
});
},
runPlan(item: PlanEntity) {
if (!$store.state.power_state) {
return;
}
2021-08-25 17:30:02 +08:00
GlobalData.getInstance().getCurrentClient()?.runPlan(item.uuid);
$q.notify({
color: "positive",
icon: "done",
message: $t.t("run plan directives send") + $t.t("success") + "!",
position: "top",
2021-12-22 11:25:04 +08:00
timeout: 1500,
2021-08-25 17:30:02 +08:00
});
},
unsetPowerOnPlan(evt: PointerEvent, uuid: string) {
evt.stopPropagation();
GlobalData.getInstance().getCurrentClient()?.setPowerOnPlan("");
},
setPowerOnPlan(evt: PointerEvent, uuid: string) {
evt.stopPropagation();
GlobalData.getInstance().getCurrentClient()?.setPowerOnPlan(uuid);
},
2021-08-25 17:30:02 +08:00
};
},
});
</script>