11<script setup lang="ts">
2- import { ref , Ref , onMounted , onBeforeUnmount , nextTick } from " vue" ;
3- import { getDirectoryInfo } from " ../api/rest" ;
4- import { selectedDirectories } from " ../store/directoryStore" ;
5- import { useRedactionPlan } from " ../store/imageStore" ;
6- import { redactionStateFlags } from " ../store/redactionStore" ;
7- import { DirectoryData , Path } from " ../store/types" ;
2+ import { ref , onMounted , onBeforeUnmount } from " vue" ;
3+ import { selectedDirectories , updateDirectories , directoryData , loadingData , calculateVisibleItems , visibleImages , remainingImages } from " ../store/directoryStore" ;
4+ import { updateTableData } from " ../store/imageStore" ;
85
96const props = defineProps ({
107 modalId: {
@@ -21,91 +18,17 @@ const modal = ref();
2118defineExpose ({ modal });
2219defineEmits ([" update-image-list" ]);
2320
24- const directoryData: Ref <DirectoryData > = ref ({
25- directory: " " ,
26- ancestors: [],
27- children: [],
28- childrenImages: [],
29- childrenYaml: [],
30- });
31-
32- const loadingData = ref (false );
33-
34- const updateDirectories = async (currentDirectory ? : string ) => {
35- directoryData .value .children = [];
36- directoryData .value .childrenImages = [];
37- directoryData .value .childrenYaml = [];
38- const timeout = setTimeout (() => {
39- loadingData .value = true ;
40- }, 100 );
41-
42- const data = await getDirectoryInfo (currentDirectory );
43- clearTimeout (timeout );
44- loadingData .value = false ;
45- directoryData .value = await {
46- ... data ,
47- children: data .child_directories ,
48- childrenImages: data .child_images ,
49- childrenYaml: data .child_yaml_files ,
50- };
51- loadingData .value = false ;
52- calculateVisibleItems ();
53- };
54- updateDirectories ();
55-
5621const closeModal = () => {
5722 modal .value .close ();
5823};
5924
60- const updateTableData = () => {
61- redactionStateFlags .value .redactionSnackbar = false ;
62- useRedactionPlan .updateImageData ({
63- directory: selectedDirectories .value .inputDirectory ,
64- rules: selectedDirectories .value .rulesetDirectory ,
65- limit: 50 ,
66- offset: 0 ,
67- update: false ,
68- });
69- };
70- const updateSelectedDirectories = async (path : string ) => {
25+ const updateSelectedDirectories = (path : string ) => {
7126 selectedDirectories .value [props .modalId ] = path ;
27+ localStorage .setItem (' inputDirectory' , selectedDirectories .value .inputDirectory );
28+ localStorage .setItem (' outputDirectory' , selectedDirectories .value .outputDirectory );
29+ localStorage .setItem (' rulesetDirectory' , selectedDirectories .value .rulesetDirectory );
7230};
7331
74- const visibleImages: Ref <Path []> = ref ([]);
75- const remainingImages = ref (0 );
76-
77- const calculateVisibleItems = () => {
78- const menuTop = document .querySelector (" .menu-top" );
79- const listContainer = document .querySelector (" .list-container" );
80- // Determine and set the height of the list container
81- listContainer ?.setAttribute (
82- " style" ,
83- ` height: calc(100% - (${menuTop ?.clientHeight }px + 3.5rem)) ` ,
84- );
85-
86- nextTick (() => {
87- const listItems = listContainer ?.querySelectorAll (" li" );
88- const containerHeight = listContainer ?.clientHeight ;
89- const listHeight = ref (0 );
90- const visibleItems = ref (0 );
91- // Determine the height of each list item
92- const listItemHeight = listItems && listItems [0 ] ? listItems [0 ].clientHeight : 0 ;
93-
94- directoryData .value .childrenImages .forEach (() => {
95- listHeight .value += listItemHeight ;
96- if (containerHeight && listHeight .value < containerHeight ) {
97- visibleItems .value += 1 ;
98- }
99- });
100-
101- visibleImages .value = directoryData .value .childrenImages .slice (
102- 0 ,
103- visibleItems .value ,
104- );
105- remainingImages .value =
106- directoryData .value .childrenImages .length - visibleItems .value ;
107- });
108- };
10932onMounted (() => {
11033 calculateVisibleItems ();
11134 window .addEventListener (" resize" , calculateVisibleItems );
@@ -129,9 +52,17 @@ onBeforeUnmount(() => {
12952 class =" btn btn-primary float-right text-white uppercase"
13053 type =" button"
13154 @click ="
132- $emit('update-image-list'),
133- closeModal(),
134- title !== 'Output Directory' ? updateTableData() : ''
55+ ($emit('update-image-list'),
56+ closeModal(),
57+ title !== 'Output Directory'
58+ ? updateTableData({
59+ directory: selectedDirectories.inputDirectory,
60+ rules: selectedDirectories.rulesetDirectory,
61+ limit: 50,
62+ offset: 0,
63+ update: false,
64+ })
65+ : '')
13566 "
13667 >
13768 Select
@@ -153,8 +84,8 @@ onBeforeUnmount(() => {
15384 v-else
15485 class =" text-blue-700"
15586 @click ="
156- updateDirectories(ancestor.path),
157- updateSelectedDirectories(ancestor.path)
87+ ( updateDirectories(ancestor.path),
88+ updateSelectedDirectories(ancestor.path) )
15889 "
15990 >
16091 {{ ancestor.name ? ancestor.name : "/" }}
@@ -232,7 +163,23 @@ onBeforeUnmount(() => {
232163 </div >
233164 </div >
234165 <form method =" dialog" class =" modal-backdrop w-screen h-screen absolute" >
235- <button >close</button >
166+ <button
167+ @click ="
168+ ($emit('update-image-list'),
169+ closeModal(),
170+ title !== 'Output Directory'
171+ ? updateTableData({
172+ directory: selectedDirectories.inputDirectory,
173+ rules: selectedDirectories.rulesetDirectory,
174+ limit: 50,
175+ offset: 0,
176+ update: false,
177+ })
178+ : '')
179+ "
180+ >
181+ close
182+ </button >
236183 </form >
237184 </dialog >
238185</template >
0 commit comments