summaryrefslogtreecommitdiff
path: root/pharo-mooc/tiny-blog/src/TinyBlog-Components/TBPostsListComponent.class.st
blob: 82a9a737c14e9468e9cea5c2a2b06eb9fa0e00f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
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 ]
]