Extension { #name : #LeDatabase } { #category : #'*MiniDocs' } LeDatabase >> addPageFromMarkdeep: markdeepDocTree withRemote: externalDocLocation [ | 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 ] ] ]. remoteMetadata := Markdeep new metadataFromXML: markdeepDocTree. page := LePage new title: (remoteMetadata at: 'title'); 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)); createEmail: (LeEmail new email:(remoteMetadata at: 'creator')); editEmail: (LeEmail new email:(remoteMetadata at: 'modifier')). snippets do: [ :snippet | page addSnippet: snippet ]. page children do: [ :snippet | (self hasBlockUID: (snippet uid)) ifTrue: [ | existingPage | existingPage := self pages detect: [ :pageTemp | pageTemp includesSnippetUid: snippet uid ]. self importErrorMessage: existingPage. ^ self ] ifFalse: [ snippet database: self. self registerSnippet: snippet ] ]. self addPage: page. ^ page ] { #category : #'*MiniDocs' } LeDatabase >> addPageFromMarkdeepUrl: aString [ | page | page := self detectLocalPageForRemote: aString. page ifNotNil: [ :arg | self importErrorMessage: page. ^ self ]. ^ self addPageFromMarkdeep: (self docTreeForLink: aString) withRemote: aString ] { #category : #'*MiniDocs' } LeDatabase >> detectLocalPageForRemote: markdeepDocUrl [ | markdeepHelper id remoteMetadata docTree | markdeepHelper := Markdeep new. docTree := self docTreeForLink: markdeepDocUrl. remoteMetadata := markdeepHelper metadataFromXML: docTree. id := remoteMetadata at: 'id' ifAbsent: [ nil ]. ^ self pageWithID: id ifAbsent: [ ^ nil ]. ] { #category : #'*MiniDocs' } LeDatabase >> docTreeForLink: aString [ ^ (XMLHTMLParser on: aString asUrl retrieveContents) parseDocument ] { #category : #'*MiniDocs' } LeDatabase >> errorCardFor: errorMessage [ | keepButton overwriteButton backupButton errorMessageUI | keepButton := BrButton new aptitude: BrGlamorousButtonWithIconAndLabelAptitude; beTinySize; label: 'Keep existing local page'; icon: BrGlamorousVectorIcons cancel; action: [ :aButton | ]; margin: (BlInsets left: 10). overwriteButton := BrButton new aptitude: BrGlamorousButtonWithIconAndLabelAptitude; beTinySize; label: 'Overwrite with remote page'; icon: BrGlamorousVectorIcons edit; action: [ :aButton | ]; margin: (BlInsets left: 10). backupButton := BrButton new aptitude: BrGlamorousButtonWithIconAndLabelAptitude; beTinySize; label: 'Backup local page'; icon: BrGlamorousVectorIcons changes; action: [ :aButton | ]; margin: (BlInsets left: 10). errorMessageUI := BrEditor new aptitude: BrGlamorousRegularEditorAptitude new ; text: errorMessage; vFitContent. ^ { errorMessageUI. keepButton. overwriteButton. backupButton } ] { #category : #'*MiniDocs' } LeDatabase >> errors [ ^ self optionAt: 'errors' ifAbsent: [ self optionAt: 'errors' put: Dictionary new ] ] { #category : #'*MiniDocs' } LeDatabase >> gtViewErrorDetailsOn: aView [ ^ 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 addChildren: (self errorCardFor: self errors associations first value) "container addChild: self asCardElement "]. ] { #category : #'*MiniDocs' } LeDatabase >> importErrorMessage: page [ | message id | id := page uidString. message := String streamContents: [ :stream | stream nextPutAll: 'IMPORTATION ERROR: A page with '; nextPut: Character lf; nextPutAll: ' id: ' , id; nextPut: Character lf; nextPutAll: ' title: ' , page contentAsString; nextPut: Character lf; nextPut: Character lf; nextPutAll: 'already exists in this database and includes overlapping contents'; nextPut: Character lf; nextPutAll: 'with the page you are trying to import.'; nextPut: Character lf; nextPut: Character lf; nextPutAll: 'Please choose one of the following options to addres the issue: ' ]. self errors at: id put: message ] { #category : #'*MiniDocs' } LeDatabase >> options [ ^ options ]