2022-09-21 18:57:52 +00:00
|
|
|
Extension { #name : #LeDatabase }
|
|
|
|
|
|
|
|
{ #category : #'*MiniDocs' }
|
2022-10-09 21:26:33 +00:00
|
|
|
LeDatabase >> addPageFromMarkdeep: markdeepDocTree withRemote: externalDocLocation [
|
2022-09-29 23:54:23 +00:00
|
|
|
|
|
|
|
| remoteMetadata divSnippets snippets page |
|
|
|
|
divSnippets := (markdeepDocTree xpath: '//div[@st-class]')
|
|
|
|
asOrderedCollection collect: [ :xmlElement | xmlElement postCopy ].
|
|
|
|
snippets := divSnippets collect: [ :xmlElement |
|
|
|
|
(xmlElement attributes at: 'st-class') = 'LeTextSnippet'
|
|
|
|
ifTrue: [ LeTextSnippet new contentFrom: xmlElement ]
|
|
|
|
ifFalse: [ (xmlElement attributes at: 'st-class') = 'LePharoSnippet'
|
|
|
|
ifTrue: [ LePharoSnippet new contentFrom: xmlElement ]
|
|
|
|
]
|
|
|
|
].
|
2022-09-22 02:15:11 +00:00
|
|
|
remoteMetadata := Markdeep new metadataFromXML: markdeepDocTree.
|
|
|
|
page := LePage new
|
|
|
|
title: (remoteMetadata at: 'title');
|
2022-10-03 17:14:48 +00:00
|
|
|
basicUid: (UUID fromString36: (remoteMetadata at: 'id'));
|
|
|
|
createTime: (LeTime new time: ((remoteMetadata at: 'created') asDateAndTime));
|
|
|
|
editTime: (LeTime new time: ((remoteMetadata at: 'modified') asDateAndTime));
|
|
|
|
latestEditTime: (LeTime new time: ((remoteMetadata at: 'modified') asDateAndTime));
|
2022-10-07 18:38:56 +00:00
|
|
|
createEmail: (LeEmail new email:(remoteMetadata at: 'creator'));
|
|
|
|
editEmail: (LeEmail new email:(remoteMetadata at: 'modifier')).
|
2022-09-29 23:54:23 +00:00
|
|
|
snippets do: [ :snippet | page addSnippet: snippet ].
|
2022-10-09 21:26:33 +00:00
|
|
|
page children do: [ :snippet |
|
2022-10-07 19:13:28 +00:00
|
|
|
(self hasBlockUID: (snippet uid))
|
2022-10-07 19:37:56 +00:00
|
|
|
ifTrue: [ | existingPage |
|
2022-10-09 01:59:57 +00:00
|
|
|
existingPage := self pages detect: [ :pageTemp | pageTemp includesSnippetUid: snippet uid ].
|
|
|
|
self importErrorMessage: existingPage.
|
|
|
|
^ self ]
|
2022-10-07 19:13:28 +00:00
|
|
|
ifFalse: [
|
|
|
|
snippet database: self.
|
|
|
|
self registerSnippet: snippet ] ].
|
2022-10-03 22:50:44 +00:00
|
|
|
self addPage: page.
|
2022-09-29 23:54:23 +00:00
|
|
|
^ page
|
2022-09-21 18:57:52 +00:00
|
|
|
]
|
|
|
|
|
2022-09-29 13:20:56 +00:00
|
|
|
{ #category : #'*MiniDocs' }
|
|
|
|
LeDatabase >> addPageFromMarkdeepUrl: aString [
|
|
|
|
| page |
|
|
|
|
page := self detectLocalPageForRemote: aString.
|
2022-10-09 21:26:33 +00:00
|
|
|
page
|
|
|
|
ifNotNil: [ :arg |
|
|
|
|
self importErrorMessage: page.
|
|
|
|
^ self ].
|
|
|
|
^ self addPageFromMarkdeep: (self docTreeForLink: aString) withRemote: aString
|
2022-09-29 13:20:56 +00:00
|
|
|
]
|
|
|
|
|
2022-09-21 18:57:52 +00:00
|
|
|
{ #category : #'*MiniDocs' }
|
|
|
|
LeDatabase >> detectLocalPageForRemote: markdeepDocUrl [
|
|
|
|
| markdeepHelper id remoteMetadata docTree |
|
|
|
|
markdeepHelper := Markdeep new.
|
2022-09-21 21:15:13 +00:00
|
|
|
docTree := self docTreeForLink: markdeepDocUrl.
|
2022-09-21 18:57:52 +00:00
|
|
|
remoteMetadata := markdeepHelper metadataFromXML: docTree.
|
2022-09-21 21:15:13 +00:00
|
|
|
id := remoteMetadata at: 'id' ifAbsent: [ nil ].
|
|
|
|
^ self pageWithID: id ifAbsent: [ ^ nil ].
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #'*MiniDocs' }
|
|
|
|
LeDatabase >> docTreeForLink: aString [
|
2022-09-22 02:15:11 +00:00
|
|
|
^ (XMLHTMLParser on: aString asUrl retrieveContents) parseDocument
|
2022-09-21 18:57:52 +00:00
|
|
|
]
|
|
|
|
|
2022-10-07 22:46:47 +00:00
|
|
|
{ #category : #'*MiniDocs' }
|
|
|
|
LeDatabase >> errorCardFor: errorMessage [
|
|
|
|
|
|
|
|
| keepButton overwriteButton backupButton errorMessageUI |
|
|
|
|
keepButton := BrButton new
|
|
|
|
aptitude: BrGlamorousButtonWithIconAndLabelAptitude;
|
|
|
|
beTinySize;
|
2022-10-09 01:59:57 +00:00
|
|
|
label: 'Keep existing local page';
|
2022-10-07 22:46:47 +00:00
|
|
|
icon: BrGlamorousVectorIcons cancel;
|
|
|
|
action: [ :aButton | ];
|
|
|
|
margin: (BlInsets left: 10).
|
|
|
|
overwriteButton := BrButton new
|
|
|
|
aptitude: BrGlamorousButtonWithIconAndLabelAptitude;
|
|
|
|
beTinySize;
|
2022-10-09 01:59:57 +00:00
|
|
|
label: 'Overwrite with remote page';
|
2022-10-07 22:46:47 +00:00
|
|
|
icon: BrGlamorousVectorIcons edit;
|
|
|
|
action: [ :aButton | ];
|
|
|
|
margin: (BlInsets left: 10).
|
|
|
|
backupButton := BrButton new
|
|
|
|
aptitude: BrGlamorousButtonWithIconAndLabelAptitude;
|
|
|
|
beTinySize;
|
2022-10-09 01:59:57 +00:00
|
|
|
label: 'Backup local page';
|
2022-10-07 22:46:47 +00:00
|
|
|
icon: BrGlamorousVectorIcons changes;
|
|
|
|
action: [ :aButton | ];
|
|
|
|
margin: (BlInsets left: 10).
|
|
|
|
|
|
|
|
errorMessageUI := BrEditor new
|
2022-10-09 01:59:57 +00:00
|
|
|
aptitude: BrGlamorousRegularEditorAptitude new ;
|
2022-10-07 22:46:47 +00:00
|
|
|
text: errorMessage;
|
|
|
|
vFitContent.
|
|
|
|
^ { errorMessageUI. keepButton. overwriteButton. backupButton }
|
|
|
|
]
|
|
|
|
|
2022-10-07 22:34:04 +00:00
|
|
|
{ #category : #'*MiniDocs' }
|
|
|
|
LeDatabase >> errors [
|
|
|
|
|
|
|
|
^ self optionAt: 'errors' ifAbsent: [ self optionAt: 'errors' put: Dictionary new ]
|
|
|
|
]
|
|
|
|
|
2022-10-07 20:48:54 +00:00
|
|
|
{ #category : #'*MiniDocs' }
|
|
|
|
LeDatabase >> gtViewErrorDetailsOn: aView [
|
|
|
|
<gtView>
|
|
|
|
^ aView explicit
|
|
|
|
title: 'Errors' translated;
|
|
|
|
priority: 5;
|
|
|
|
stencil: [
|
|
|
|
| container |
|
|
|
|
container := BlElement new
|
|
|
|
layout: BlFlowLayout new;
|
|
|
|
constraintsDo: [ :c |
|
|
|
|
c vertical fitContent.
|
|
|
|
c horizontal matchParent ];
|
|
|
|
padding: (BlInsets all: 10).
|
|
|
|
container
|
2022-10-07 22:34:04 +00:00
|
|
|
addChildren: (self errorCardFor: self errors associations first value)
|
2022-10-07 20:48:54 +00:00
|
|
|
"container addChild: self asCardElement "].
|
|
|
|
]
|
|
|
|
|
2022-09-21 18:57:52 +00:00
|
|
|
{ #category : #'*MiniDocs' }
|
|
|
|
LeDatabase >> importErrorMessage: page [
|
|
|
|
|
2022-10-07 22:34:04 +00:00
|
|
|
| message id |
|
|
|
|
id := page uidString.
|
|
|
|
message := String streamContents: [ :stream |
|
2022-09-21 18:57:52 +00:00
|
|
|
stream
|
2022-10-09 01:59:57 +00:00
|
|
|
nextPutAll: 'IMPORTATION ERROR: A page with
|
|
|
|
';
|
2022-09-21 18:57:52 +00:00
|
|
|
nextPut: Character lf;
|
2022-10-07 22:34:04 +00:00
|
|
|
nextPutAll: ' id: ' , id;
|
2022-09-21 18:57:52 +00:00
|
|
|
nextPut: Character lf;
|
|
|
|
nextPutAll: ' title: ' , page contentAsString;
|
|
|
|
nextPut: Character lf;
|
|
|
|
nextPut: Character lf;
|
2022-10-09 01:59:57 +00:00
|
|
|
nextPutAll: 'already exists in this database and includes overlapping contents';
|
|
|
|
nextPut: Character lf;
|
|
|
|
nextPutAll: 'with the page you are trying to import.';
|
2022-09-21 18:57:52 +00:00
|
|
|
nextPut: Character lf;
|
|
|
|
nextPut: Character lf;
|
|
|
|
nextPutAll:
|
2022-10-09 01:59:57 +00:00
|
|
|
'Please choose one of the following options to addres the issue:
|
|
|
|
' ].
|
2022-10-07 22:34:04 +00:00
|
|
|
self errors at: id put: message
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #'*MiniDocs' }
|
|
|
|
LeDatabase >> options [
|
|
|
|
|
|
|
|
^ options
|
2022-09-21 18:57:52 +00:00
|
|
|
]
|