diff options
| author | Eugen Wissner <belka@caraus.de> | 2025-11-21 22:20:10 +0100 |
|---|---|---|
| committer | Eugen Wissner <belka@caraus.de> | 2025-11-21 22:20:10 +0100 |
| commit | c03c9f8b886c0e8eca5a701c0ca941e05e0b6285 (patch) | |
| tree | 5f27293563caa042b182de97fe59b22e2cbd533a /pharo-mooc/tiny-blog/src/TinyBlog-Components/TBPostsListComponent.class.st | |
| parent | c0336dac8effb57c04221f23b72bff70170933c5 (diff) | |
| download | book-exercises-c03c9f8b886c0e8eca5a701c0ca941e05e0b6285.tar.gz | |
Add pharo tiny blog
Diffstat (limited to 'pharo-mooc/tiny-blog/src/TinyBlog-Components/TBPostsListComponent.class.st')
| -rw-r--r-- | pharo-mooc/tiny-blog/src/TinyBlog-Components/TBPostsListComponent.class.st | 142 |
1 files changed, 142 insertions, 0 deletions
diff --git a/pharo-mooc/tiny-blog/src/TinyBlog-Components/TBPostsListComponent.class.st b/pharo-mooc/tiny-blog/src/TinyBlog-Components/TBPostsListComponent.class.st new file mode 100644 index 0000000..82a9a73 --- /dev/null +++ b/pharo-mooc/tiny-blog/src/TinyBlog-Components/TBPostsListComponent.class.st @@ -0,0 +1,142 @@ +Class { + #name : 'TBPostsListComponent', + #superclass : 'TBScreenComponent', + #instVars : [ + 'postComponents', + 'currentCategory', + 'showLoginError' + ], + #category : 'TinyBlog-Components', + #package : 'TinyBlog-Components' +} + +{ #category : 'rendering' } +TBPostsListComponent >> basicRenderCategoriesOn: html [ + html render: self categoriesComponent +] + +{ #category : 'rendering' } +TBPostsListComponent >> basicRenderPostsOn: html [ + self readSelectedPosts do: [ :p | html render: (self postComponentFor: p) ] +] + +{ #category : 'rendering' } +TBPostsListComponent >> categoriesComponent [ + ^ TBCategoriesComponent + categories: self blog allCategories + postsList: self +] + +{ #category : 'initialization' } +TBPostsListComponent >> children [ + ^ self postComponents, super children +] + +{ #category : 'accessing' } +TBPostsListComponent >> currentCategory [ + + ^ currentCategory +] + +{ #category : 'accessing' } +TBPostsListComponent >> currentCategory: anObject [ + + currentCategory := anObject +] + +{ #category : 'as yet unclassified' } +TBPostsListComponent >> goToAdministrationView [ + self call: TBAdminComponent new +] + +{ #category : 'as yet unclassified' } +TBPostsListComponent >> hasLoginError [ + ^ showLoginError ifNil: [ false ] +] + +{ #category : 'initialization' } +TBPostsListComponent >> initialize [ + super initialize. + postComponents := OrderedCollection new +] + +{ #category : 'as yet unclassified' } +TBPostsListComponent >> loginErrorMessage [ + ^ 'Incorrect login and/or password' +] + +{ #category : 'as yet unclassified' } +TBPostsListComponent >> loginErrorOccurred [ + showLoginError := true +] + +{ #category : 'rendering' } +TBPostsListComponent >> postComponentFor: aPost [ + ^ TBPostComponent new post: aPost +] + +{ #category : 'initialization' } +TBPostsListComponent >> postComponents [ + postComponents := self readSelectedPosts + collect: [ :each | TBPostComponent new post: each ]. + ^ postComponents +] + +{ #category : 'initialization' } +TBPostsListComponent >> readSelectedPosts [ + ^ self currentCategory + ifNil: [ self blog allVisibleBlogPosts ] + ifNotNil: [ self blog allVisibleBlogPostsFromCategory: self currentCategory ] +] + +{ #category : 'rendering' } +TBPostsListComponent >> renderCategoryColumnOn: html [ + html column + extraSmallSize: 12; + smallSize: 2; + mediumSize: 4; + with: [ self basicRenderCategoriesOn: html ] +] + +{ #category : 'rendering' } +TBPostsListComponent >> renderContentOn: html [ + super renderContentOn: html. + html container: [ + html row + with: [ + html column + extraSmallSize: 12; + smallSize: 2; + mediumSize: 4; + with: [ html render: self categoriesComponent ]. + self renderPostColumnOn: html ] ] +] + +{ #category : 'rendering' } +TBPostsListComponent >> renderLoginErrorMessageIfAnyOn: html [ + self hasLoginError ifTrue: [ + showLoginError := false. + html alert + beDanger; + with: self loginErrorMessage ] +] + +{ #category : 'rendering' } +TBPostsListComponent >> renderPostColumnOn: html [ + html column + extraSmallSize: 12; + smallSize: 10; + mediumSize: 8; + with: [ + self renderLoginErrorMessageIfAnyOn: html. + self basicRenderPostsOn: html ] +] + +{ #category : 'as yet unclassified' } +TBPostsListComponent >> tryConnectionWithLogin: login andPassword: password [ + (login = self blog administrator login and: [ (SHA256 hashMessage: password) = self blog administrator password ]) + ifTrue: [ + self session currentAdmin: self blog administrator. + self goToAdministrationView ] + ifFalse: [ self loginErrorOccurred ] +] |
