|
1 | 1 | import { createStore } from 'vuex'
|
2 | 2 | import { iiifManifest2mei, checkIiifManifest, getPageArray } from '@/tools/iiif.js'
|
3 | 3 | import { meiZone2annotorious, annotorious2meiZone, measureDetector2meiZone, generateMeasure, insertMeasure, addZoneToLastMeasure, deleteZone, setMultiRest, createNewMdiv, moveContentToMdiv, toggleAdditionalZone, addImportedPage } from '@/tools/meiMappings.js'
|
| 4 | +import { toRaw } from 'vue'; |
4 | 5 |
|
5 | 6 | import { mode as allowedModes } from '@/store/constants.js'
|
6 | 7 | import qs from 'qs';
|
@@ -60,7 +61,9 @@ export default createStore({
|
60 | 61 | importingImages: [],
|
61 | 62 | currentMeasureId: null,
|
62 | 63 | username: null,// used for the MeasureModal
|
63 |
| - infoJson: [] |
| 64 | + infoJson: [], |
| 65 | + currentheight: "", |
| 66 | + currentwidth: "" |
64 | 67 |
|
65 | 68 | // TODO isScore: true
|
66 | 69 | },
|
@@ -115,7 +118,18 @@ export default createStore({
|
115 | 118 | SET_USERNAME(state, username) {
|
116 | 119 | state.username = username
|
117 | 120 | },
|
| 121 | + SET_CURRENT_WIDTH(state, height) { |
| 122 | + state.currentheight = height |
| 123 | + }, |
| 124 | + SET_CURRENT_HEIGHT(state, width) { |
| 125 | + state.currentheight = width |
| 126 | + }, |
| 127 | + SET_PAGE_ARRAY(state, updatedArray) { |
| 128 | + state.pages = toRaw(updatedArray) |
| 129 | + console.log("this is the updated array ", state.pages) |
| 130 | + }, |
118 | 131 | SET_CURRENT_PAGE(state, i) {
|
| 132 | + console.log("current page is ", state.currentPage) |
119 | 133 | console.log("page is changed ", state.pages.length)
|
120 | 134 | if (i > -1 && i < state.pages.length) {
|
121 | 135 | state.currentPage = i
|
@@ -296,6 +310,13 @@ export default createStore({
|
296 | 310 | state.xmlDoc = xmlDoc
|
297 | 311 | }
|
298 | 312 | },
|
| 313 | + SET_PAGE_DIMENSIONS(state, { index, width, height }) { |
| 314 | + console.log("width is ", width) |
| 315 | + |
| 316 | + // Ensure the update is reactive |
| 317 | + state.pages[index].width = width; |
| 318 | + state.pages[index].height = height; |
| 319 | + }, |
299 | 320 | CREATE_NEW_MDIV(state) {
|
300 | 321 | const xmlDoc = state.xmlDoc.cloneNode(true)
|
301 | 322 | state.currentMdivId = createNewMdiv(xmlDoc, state.currentMdivId)
|
@@ -380,6 +401,7 @@ export default createStore({
|
380 | 401 | console.log("this is branch " + branch)
|
381 | 402 | state.branch = branch
|
382 | 403 | },
|
| 404 | + |
383 | 405 | },
|
384 | 406 | actions: {
|
385 | 407 | async fetchDirectories({ state, commit }) {
|
@@ -484,6 +506,16 @@ export default createStore({
|
484 | 506 | console.log('setting current page to ' + i)
|
485 | 507 | commit('SET_CURRENT_PAGE', i)
|
486 | 508 | },
|
| 509 | + setWidth({ commit }, width) { |
| 510 | + commit('SET_CURRENT_WIDTH', width) |
| 511 | + }, |
| 512 | + setHeight({ commit }, height) { |
| 513 | + commit('SET_CURRENT_HEIGHT', height) |
| 514 | + }, |
| 515 | + updatePage({ commit }, upatedArr) { |
| 516 | + console.log("hi everyone") |
| 517 | + commit('SET_PAGE_ARRAY', upatedArr) |
| 518 | + }, |
487 | 519 | setCurrentPageZone({ commit }, j) {
|
488 | 520 | commit('SET_TOTAL_ZONES_COUNT', j)
|
489 | 521 | },
|
@@ -796,151 +828,38 @@ export default createStore({
|
796 | 828 | commit('SET_BRANCH', branch)
|
797 | 829 | },
|
798 | 830 | importIIIF({ commit, dispatch, state }, url) {
|
799 |
| - commit('SET_LOADING', true); |
800 |
| - |
801 |
| - // Fetch the IIIF manifest |
| 831 | + commit('SET_LOADING', true) |
802 | 832 | fetch(url)
|
803 |
| - .then(res => res.json()) |
804 |
| - .then(json => { |
805 |
| - commit('SET_LOADING', false); |
806 |
| - commit('SET_PROCESSING', true); |
807 |
| - |
808 |
| - let canvases = json.sequences[0].canvases; |
809 |
| - |
810 |
| - // Process each canvas one by one, sequentially |
811 |
| - const processCanvasesSequentially = async () => { |
812 |
| - for (let i = 0; i < canvases.length; i++) { |
813 |
| - try { |
814 |
| - // Build the info.json URL for the current canvas |
815 |
| - const infoUrl = canvases[i].images[0].resource.service['@id'] + "/info.json"; |
816 |
| - |
817 |
| - // Push the URL to the state.infoJson array |
818 |
| - state.infoJson.push(infoUrl); |
819 |
| - |
820 |
| - // Fetch the info.json |
821 |
| - const res = await fetch(infoUrl); |
822 |
| - const result = await res.json(); |
823 |
| - |
824 |
| - // Check if this is a proper IIIF Manifest, then convert to MEI |
825 |
| - const isManifest = checkIiifManifest(json); |
826 |
| - if (!isManifest) { |
827 |
| - throw new Error("Invalid IIIF manifest"); |
828 |
| - } |
829 |
| - |
830 |
| - // Extract the width and height from the result |
831 |
| - const width = result.width; |
832 |
| - const height = result.height; |
833 |
| - |
834 |
| - // Push the dimensions into the state.pageDimension array |
835 |
| - state.pageDimension.push([width, height]); |
836 |
| - |
837 |
| - } catch (error) { |
838 |
| - console.error(`Error processing canvas ${i}:`, error); |
839 |
| - throw error; // This will stop the loop and be caught in the outer catch block |
840 |
| - } |
841 |
| - } |
842 |
| - }; |
843 |
| - |
844 |
| - // Call the sequential processing function |
845 |
| - processCanvasesSequentially() |
846 |
| - .then(() => { |
847 |
| - // After processing all canvases, convert the manifest to MEI |
848 |
| - return iiifManifest2mei(json, url, parser, state); |
849 |
| - }) |
850 |
| - .then(mei => { |
851 |
| - // Dispatch setData with the generated MEI |
852 |
| - dispatch('setData', mei); |
853 |
| - }) |
854 |
| - .catch(err => { |
855 |
| - console.error('Error processing IIIF manifest or canvases:', err); |
856 |
| - commit('SET_LOADING', false); |
857 |
| - // Add any additional error messaging here |
858 |
| - }) |
859 |
| - .finally(() => { |
860 |
| - commit('SET_PROCESSING', false); // Ensure processing is set to false after completion |
861 |
| - }); |
| 833 | + .then(res => { |
| 834 | + return res.json() |
862 | 835 | })
|
863 |
| - .catch(error => { |
864 |
| - // Handle errors in the initial IIIF manifest fetch |
865 |
| - console.error('Error fetching IIIF manifest:', error); |
866 |
| - commit('SET_LOADING', false); |
867 |
| - }); |
868 |
| - }, |
869 |
| - importIIIF({ commit, dispatch, state }, url) { |
870 |
| - commit('SET_LOADING', true); |
871 |
| - |
872 |
| - // Fetch the IIIF manifest |
873 |
| - fetch(url) |
874 |
| - .then(res => res.json()) |
875 | 836 | .then(json => {
|
876 |
| - commit('SET_LOADING', false); |
877 |
| - commit('SET_PROCESSING', true); |
878 |
| - |
879 |
| - let canvases = json.sequences[0].canvases; |
880 |
| - |
881 |
| - // Map all canvas images to their info.json URLs |
882 |
| - const infoJsonUrls = canvases.map(canvas => { |
883 |
| - return canvas.images[0].resource.service['@id'] + "/info.json"; |
884 |
| - }); |
885 |
| - |
886 |
| - // Store all fetch promises for info.json |
887 |
| - const fetchPromises = infoJsonUrls.map((infoUrl) => { |
888 |
| - return fetch(infoUrl) |
889 |
| - .then(res => res.json()) |
890 |
| - .then(result => { |
891 |
| - // Check if this is a proper IIIF Manifest |
892 |
| - const isManifest = checkIiifManifest(json); |
893 |
| - if (!isManifest) { |
894 |
| - throw new Error("Invalid IIIF manifest"); |
895 |
| - } |
896 |
| - |
897 |
| - // Extract the width and height from the result |
898 |
| - const width = result.width; |
899 |
| - const height = result.height; |
900 |
| - |
901 |
| - // Return both the infoUrl and the dimensions |
902 |
| - return { infoUrl, dimensions: [width, height] }; |
903 |
| - }) |
904 |
| - .catch(error => { |
905 |
| - console.error(`Error fetching ${infoUrl}:`, error); |
906 |
| - // Return a fallback object in case of error, to keep the promise chain going |
907 |
| - return { infoUrl, dimensions: [null, null], error: true }; |
908 |
| - }); |
909 |
| - }); |
910 |
| - |
911 |
| - // Use Promise.allSettled to fetch all info.json files concurrently and wait for all of them |
912 |
| - Promise.allSettled(fetchPromises) |
913 |
| - .then((results) => { |
914 |
| - // Update state.infoJson and state.pageDimension in batches |
915 |
| - results.forEach(result => { |
916 |
| - if (result.status === 'fulfilled') { |
917 |
| - state.infoJson.push(result.value.infoUrl); |
918 |
| - state.pageDimension.push(result.value.dimensions); |
919 |
| - } |
920 |
| - }); |
921 |
| - |
922 |
| - // After processing all canvases, convert the manifest to MEI |
923 |
| - return iiifManifest2mei(json, url, parser, state); |
924 |
| - }) |
| 837 | + commit('SET_LOADING', false) |
| 838 | + commit('SET_PROCESSING', true) |
| 839 | + // check if this is a proper IIIF Manifest, then convert to MEI |
| 840 | + const isManifest = checkIiifManifest(json) |
| 841 | + console.log('isManifest: ' + isManifest) |
| 842 | + if (!isManifest) { |
| 843 | + // do some error handling |
| 844 | + return false |
| 845 | + } |
| 846 | + |
| 847 | + iiifManifest2mei(json, url, parser, state) |
925 | 848 | .then(mei => {
|
926 |
| - // Dispatch setData with the generated MEI |
927 |
| - dispatch('setData', mei); |
| 849 | + dispatch('setData', mei) |
928 | 850 | })
|
929 |
| - .catch(err => { |
930 |
| - console.error('Error processing IIIF manifest or canvases:', err); |
931 |
| - commit('SET_LOADING', false); |
932 |
| - // Add any additional error messaging here |
933 |
| - }) |
934 |
| - .finally(() => { |
935 |
| - commit('SET_PROCESSING', false); // Ensure processing is set to false after completion |
936 |
| - }); |
937 | 851 | })
|
938 |
| - .catch(error => { |
939 |
| - // Handle errors in the initial IIIF manifest fetch |
940 |
| - console.error('Error fetching IIIF manifest:', error); |
941 |
| - commit('SET_LOADING', false); |
942 |
| - }); |
| 852 | + .catch(err => { |
| 853 | + commit('SET_LOADING', false) |
| 854 | + console.log(err) |
| 855 | + // add some error message |
| 856 | + }) |
| 857 | + }, |
| 858 | + updatePageDimensions({ commit }, { index, width, height }) { |
| 859 | + commit('SET_PAGE_DIMENSIONS', { index, width, height }); |
| 860 | + |
943 | 861 | },
|
| 862 | + |
944 | 863 |
|
945 | 864 | importXML({ commit, dispatch }, mei) {
|
946 | 865 | fetch(mei)
|
@@ -1221,13 +1140,12 @@ export default createStore({
|
1221 | 1140 | pages: state => {
|
1222 | 1141 | const arr = []
|
1223 | 1142 | state.pages.forEach(page => {
|
1224 |
| - console.log("this is the page width and height at index", page.width, " " , page.height) |
| 1143 | + |
1225 | 1144 | const obj = {
|
1226 | 1145 | tileSource: page.uri,
|
1227 |
| - width: page.width, |
1228 |
| - x: 0, |
1229 |
| - y: 0 |
| 1146 | + width: page.width |
1230 | 1147 | }
|
| 1148 | + console.log("current width is ", state.currentwidth) |
1231 | 1149 | arr.push(obj)
|
1232 | 1150 | })
|
1233 | 1151 | return arr
|
|
0 commit comments