From c03c9f8b886c0e8eca5a701c0ca941e05e0b6285 Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Fri, 21 Nov 2025 22:20:10 +0100 Subject: Add pharo tiny blog --- .../TBPostsListComponent.class.st | 142 +++++++++++++++++++++ 1 file changed, 142 insertions(+) create mode 100644 pharo-mooc/tiny-blog/src/TinyBlog-Components/TBPostsListComponent.class.st (limited to 'pharo-mooc/tiny-blog/src/TinyBlog-Components/TBPostsListComponent.class.st') 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 ] +] -- cgit v1.2.3