Grafoscopio/src/Grafoscopio-ExternalTools/FossilTimeline.class.st

92 lines
2.3 KiB
Smalltalk

"
I store all commits in a fossil timeline.
- message one
- message two
- what is the way to create instances is a plus.
One simple example is simply gorgeous.
Internal Representation and Key Implementation Points.
Instance Variables
commits: <Object>
Implementation Points
"
Class {
#name : #FossilTimeline,
#superclass : #Object,
#instVars : [
'commits'
],
#category : #'Grafoscopio-ExternalTools-Fossil'
}
{ #category : #accessing }
FossilTimeline >> commits [
^ commits
]
{ #category : #accessing }
FossilTimeline >> commits: anObject [
commits := anObject
]
{ #category : #'as yet unclassified' }
FossilTimeline >> importFromUrl: aJsonFileUrl [
"Imports all commits stored in aJsonFileUrl and converts them in a collection of FossilCommit objects"
| commitsDict |
"Extracting data"
commitsDict := ((NeoJSONReader fromString: (aJsonFileUrl asUrl retrieveContents asString)) at: 'payload') at: 'timeline'.
"Adding all commits except the first one who has no parents"
self commits: (commitsDict collect: [:commit |
FossilCommit new
uuid: (commit at: 'uuid');
type: (commit at: 'type');
timestamp: (commit at: 'timestamp');
user: (commit at: 'user');
comment: (commit at: 'comment');
tags: (commit at: 'tags')]).
"Detecting which commits are on refered in the dictionary as parents and adding them as such
for the respective commit"
commitsDict allButLastDo: [:each |
(self commits detect: [:commit | commit uuid = (each at: 'uuid') ])
parents: (self commits detect: [:c | c uuid = ((each at: 'parents') at: 1) ])].
]
{ #category : #'as yet unclassified' }
FossilTimeline >> initialize [
"comment stating purpose of message"
super initialize
]
{ #category : #accessing }
FossilTimeline >> parentsFor: aCommit [
"Returns the elements which are parents for aCommit"
^ self commits select: [:commit | commit uuid = (aCommit parents at: 1)]
]
{ #category : #'as yet unclassified' }
FossilTimeline >> show [
"Shows a draft of the timeline history. Tree topologies are preserved but still needs to be group timelines by date and author of the commit"
| view |
"Visualization"
view := RTMondrian new.
view nodes: self commits.
"view nodes do: [:each | each color: Color blue]."
view edges
connectTo: #parents.
view layout tree.
^ view.
]