Skip to content

Commit c5f5cdd

Browse files
committed
fixed snapshot bug
1 parent b9c4fde commit c5f5cdd

5 files changed

Lines changed: 37 additions & 23 deletions

File tree

src/adminPage/adminSnapshots.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ async function manageSnapshots(snapshotTable) {
4444

4545
const userDiv = document.createElement('div')
4646
userDiv.setAttribute('class', 'nameDiv')
47-
const snapshotCreator = store.any(UI.rdf.sym(sortedSnapshotFileNames[i]+"#this"), UI.rdf.sym('http://purl.org/dc/terms/creator'), null)
47+
await store.fetcher.load(sortedSnapshotFileNames[i])
48+
const snapshotCreator = await store.any(UI.rdf.sym(sortedSnapshotFileNames[i]+'#this'), UI.rdf.sym('http://purl.org/dc/terms/creator'), null, UI.rdf.sym(sortedSnapshotFileNames[i]))
4849
if (snapshotCreator) {
4950
userDiv.textContent = snapshotCreator.value
5051
} else {
@@ -102,10 +103,13 @@ async function manageSnapshots(snapshotTable) {
102103
}
103104

104105
} else {
106+
const noSnapMessageDiv = document.createElement('div')
105107
const message = document.createElement('span')
106108
message.setAttribute('id', 'spanMessage')
107109
message.textContent = "The system has no snapshots yet"
108-
snapshotTable.appendChild(message)
110+
noSnapMessageDiv.appendChild(message)
111+
snapshotTable.appendChild(noSnapMessageDiv)
112+
snapshotTable.setAttribute('class', 'noSnapshots')
109113
}
110114

111115
const createSnapDiv = document.createElement('div')
@@ -124,6 +128,7 @@ async function manageSnapshots(snapshotTable) {
124128
const messageCreateSpan = document.createElement('span')
125129
messageCreateSpan.setAttribute('class', 'spanshotCreateMessage')
126130
messageCreateSpan.setAttribute('id', 'createSnap')
131+
127132
createSnapDiv.appendChild(createSnapshotButton)
128133
createSnapDiv.appendChild(messageCreateSpan)
129134

src/adminPage/snapshots/snapshot.js

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ async function snapshotsLogic(linkToKG, linkToGKsnapshotContainer, KGname, thres
88
await loadOrCreateContainer(store, linkToGKsnapshotContainer)
99
const snapshots = await getContainerMembers(store, UI.rdf.sym(linkToGKsnapshotContainer))
1010
const sortedSnapshotFileNames = snapshots.map(snapshot => snapshot.value).sort() // the first element contains the oldest content
11-
11+
1212
const currentKG = await store.fetcher.load(linkToKG)
1313

1414
if (sortedSnapshotFileNames && sortedSnapshotFileNames.length === 0) {
@@ -17,25 +17,21 @@ async function snapshotsLogic(linkToKG, linkToGKsnapshotContainer, KGname, thres
1717
const latestSnapshotLink = sortedSnapshotFileNames[sortedSnapshotFileNames.length - 1] // last element contains the newest content
1818
let latestSnapshotKG
1919
try {
20-
latestSnapshotKG = await store.fetcher?.load(latestSnapshotLink)
20+
latestSnapshotKG = await getSnapshotWithoutAdditionalTriples(store, latestSnapshotLink)
2121
} catch (err) {
2222
console.log(err)
2323
latestSnapshotKG = {}
2424
latestSnapshotKG.responseText = ''
2525
}
2626

2727
if (latestSnapshotKG.responseText !== currentKG.responseText) {
28-
//console.log(latestSnapshotKG.responseText !== currentKG.responseText)
29-
//console.log(latestSnapshotKG.responseText)
30-
//console.log(currentKG.responseText)
3128
sortedSnapshotFileNames.push(await createSnapshot(store, currentKG, KGname))
3229
}
3330
}
3431

3532
if (sortedSnapshotFileNames && sortedSnapshotFileNames.length > threshold) {
3633
deleteOlderSnapshots(store, sortedSnapshotFileNames, threshold)
3734
}
38-
3935
}
4036

4137
async function createSnapshot(store, currentKG, nameOfSnapshot) {
@@ -79,7 +75,7 @@ async function createSnapshotNow(store, linkToCurrentKG, snapName, sortedSnapsho
7975
console.info('creating snapshot')
8076
element.textContent = 'Working...'
8177
try {
82-
const currentKG = await store.fetcher?.load(linkToCurrentKG)
78+
const currentKG = await store.fetcher.load(linkToCurrentKG)
8379
sortedSnapshotFileNames.push(await createSnapshot(store, currentKG, snapName))
8480
} catch (err) {
8581
const msg = 'Something went wrong'
@@ -93,14 +89,24 @@ async function switchSnapshot(store, url, element, linkToKG) {
9389
console.info("switching snapshot")
9490
element.textContent = 'Working...'
9591
try {
96-
const snapshotKG = await store.fetcher?.load(url)
97-
await store.fetcher?.webOperation('DELETE', UI.rdf.sym(linkToKG))
98-
await store.fetcher?.webOperation('PUT', linkToKG, { data: snapshotKG.responseText, contentType: 'text/turtle', Link: '<http://www.w3.org/ns/ldp#BasicContainer>; rel="type"' })
99-
const currentKG = await store.fetcher?.load(linkToKG)
92+
const snapshotKG = await getSnapshotWithoutAdditionalTriples(store, url)
93+
await store.fetcher.webOperation('DELETE', UI.rdf.sym(linkToKG))
94+
await store.fetcher.webOperation('PUT', linkToKG, { data: snapshotKG.responseText, contentType: 'text/turtle', Link: '<http://www.w3.org/ns/ldp#BasicContainer>; rel="type"' })
95+
const currentKG = await store.fetcher.load(linkToKG)
10096
} catch (err) {
10197
const msg = 'could not switch snapshot '
10298
element.textContent = msg
10399
throw new Error(msg);
104100
}
105101
element.textContent = "Successful"
102+
}
103+
104+
async function getSnapshotWithoutAdditionalTriples(store, linkToResource) {
105+
let loadedResource = await store.fetcher.load(linkToResource)
106+
const creator = store.statementsMatching(null, UI.rdf.sym("http://purl.org/dc/terms/creator"), null, UI.rdf.sym(linkToResource))
107+
const modified = store.statementsMatching(null, UI.rdf.sym("http://purl.org/dc/terms/modified"), null, UI.rdf.sym(linkToResource))
108+
await store.updater.update(creator.concat(modified), [])
109+
loadedResource = await store.fetcher.load(linkToResource)
110+
await store.updater.update([], creator.concat(modified))
111+
return loadedResource
106112
}

src/editDataPage/editData.html

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,8 @@ <h1>Edit the Solid Hello Worlds examples</h1>
3939
<script type="text/javascript" src="../../lib/solid-ui.js"></script>
4040
<script type="text/javascript" src="../config.js"></script>
4141
<script type="text/javascript" src="./loadData.js"></script>
42-
<script type="text/javascript" src="../adminPage/snapshots/container.js"></script>
42+
<script type="text/javascript" src="../adminPage/snapshots/container.js"></script>
4343
<script type="text/javascript" src="../adminPage/snapshots/snapshot.js"></script>
44-
<!--<script type="text/javascript">
45-
document.addEventListener('DOMContentLoaded', function () {
46-
snapshotsLogic()
47-
}, false)
48-
</script>-->
4944

5045
</body>
5146

src/editDataPage/loadData.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
document.addEventListener('DOMContentLoaded', function () {
2-
snapshotsLogic(appConfig.LINK_TO_KNOWLEDGE_GRAPH, appConfig.LINK_TO_KNOWLEDGE_GRAPH_SNAPSHOTS, appConfig.KNOWLEDGE_GRAPH_SNAPSHOT_NAME, appConfig.NUMBER_OF_SNAPSHOTS )
3-
loadData()
4-
}, false)
1+
window.onload = function() {
2+
if (window.location.href.indexOf('editData.html') > -1) {
3+
snapshotsLogic(appConfig.LINK_TO_KNOWLEDGE_GRAPH, appConfig.LINK_TO_KNOWLEDGE_GRAPH_SNAPSHOTS, appConfig.KNOWLEDGE_GRAPH_SNAPSHOT_NAME, appConfig.NUMBER_OF_SNAPSHOTS)
4+
loadData()
5+
}
6+
}
57

68
function complainIfBad(ok, message) {
79
if (ok) return

src/style.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,12 @@ nav {
149149
margin: 1em;
150150
}
151151

152+
.noSnapshots {
153+
width: fit-content;
154+
text-align: center;
155+
margin-left: 12em;
156+
}
157+
152158
.snapshotTable {
153159
width: fit-content;
154160
text-align: center;

0 commit comments

Comments
 (0)