-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathNewHomePage.php
More file actions
289 lines (239 loc) · 9.87 KB
/
Copy pathNewHomePage.php
File metadata and controls
289 lines (239 loc) · 9.87 KB
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
<?php
/**
* Copyright 2020 Open Infrastructure Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
class NewHomePage extends Page
{
private static $db = [
// CLOUD INFRASTRUCTURE BLOCK
'CloudInfraTitle' => 'Text',
'CloudInfraContent' => 'HTMLText',
'CloudInfraLink' => 'Text',
// LATEST RELEASE BLOCK
"LatestReleaseName" => 'Text',
"LatestReleaseVideoLink" => 'Text',
"LatestReleaseVideoDescription" => 'Text',
"LatestReleaseCurrentButtonText" => 'Text',
"LatestReleaseCurrentButtonLink" => 'Text',
"LatestReleaseUpNextButtonText" => 'Text',
"LatestReleaseUpNextButtonLink" => 'Text',
];
private static $has_one = [
'LatestReleaseVideoPoster' => 'CloudImage',
];
private static $has_many = [
'OSFMembers' => 'OSFMember',
];
private static $many_many = [
'MarketplaceSpotLight' => 'CompanyService',
'UserStories' => 'UserStoryDO',
];
private static $many_many_extraFields = [
'UserStories' =>[
'ButtonText' => 'Text',
]
];
public function getCloudInfraTitle():string{
$res = $this->getField('CloudInfraTitle');
if(empty($res)){
$res = <<<HTML
Cloud Infrastructure for Virtual Machines, Bare Metal, and Containers
HTML;
}
return $res;
}
public function getCloudInfraContent():string{
$res = $this->getField('CloudInfraContent');
if(empty($res)){
$res = <<<HTML
Openstack controls large pools of compute, storage, and networking resources,
all managed through APIs or a dashboard. Beyond standard infrastructure-as-a-service
functionality, additional components provide orchestration, fault management and
service management amongst other services to ensure high availability of user
applications.
HTML;
}
return $res;
}
public function getCloudInfraLink(){
$res = $this->getField('CloudInfraLink');
if(empty($res)){
$res = '#';
}
return $res;
}
public function getLatestReleaseName(){
$res = $this->getField('LatestReleaseName');
if(empty($res)){
$res = 'OpenStack Ussuri';
}
return $res;
}
public function getLatestReleaseVideoLink(){
$res = $this->getField('LatestReleaseVideoLink');
if(empty($res)){
$res = '#';
}
return $res;
}
public function getLatestReleaseVideoDescription(){
$res = $this->getField('LatestReleaseVideoDescription');
if(empty($res)){
$res = 'Watch the Ussuri Community Meeting';
}
return $res;
}
public function getLatestReleaseCurrentButtonText(){
$res = $this->getField('LatestReleaseCurrentButtonText');
if(empty($res)){
$res = 'THIS RELEASE: USSURI';
}
return $res;
}
public function getLatestReleaseCurrentButtonLink(){
$res = $this->getField('LatestReleaseCurrentButtonLink');
if(empty($res)){
$res = '#';
}
return $res;
}
public function getLatestReleaseUpNextButtonText(){
$res = $this->getField('LatestReleaseUpNextButtonText');
if(empty($res)){
$res = 'UP NEXT: VICTORIA';
}
return $res;
}
public function getLatestReleaseUpNextButtonLink(){
$res = $this->getField('LatestReleaseUpNextButtonLink');
if(empty($res)){
$res = '#';
}
return $res;
}
public function getLatestReleaseVideoPosterUrl(){
if($this->LatestReleaseVideoPoster()->exists())
{
return $this->LatestReleaseVideoPoster()->Link();
}
return '/themes/openstack/home_images/Ussuri/Ussuri_1920x1080.jpg';
}
public function getRandomCompanyService(){
$list = $this->MarketplaceSpotLight()->toArray();
if(!count($list)) return null;
$index = array_rand ($list);
return $list[$index];
}
public function getCompanyServiceMarketplaceLink($id):?string{
return '#';
}
public function getRandomOSFMember(){
$list = $this->OSFMembers()->toArray();
if(!count($list)) return null;
$index = array_rand ($list);
return $list[$index];
}
function getCMSFields()
{
$fields = parent::getCMSFields();
// CLOUD INFRASTRUCTURE BLOCK
$fields->addFieldToTab('Root.CLOUD INFRASTRUCTURE BLOCK', new TextField ('CloudInfraTitle', 'Title'));
$fields->addFieldToTab('Root.CLOUD INFRASTRUCTURE BLOCK', new HtmlEditorField ('CloudInfraContent', 'Content'));
$fields->addFieldToTab('Root.CLOUD INFRASTRUCTURE BLOCK', new TextField ('CloudInfraLink', 'Link (READ MORE)'));
// LATEST RELEASE BLOCK
$fields->addFieldToTab('Root.LATEST RELEASE BLOCK', new TextField ('LatestReleaseName', 'Name'));
$fields->addFieldToTab('Root.LATEST RELEASE BLOCK', new TextField ('LatestReleaseVideoLink', 'Video Link'));
$promo_hero_image = new CustomUploadField('LatestReleaseVideoPoster', 'Video Poster');
$promo_hero_image->setFolderName('homepage');
$promo_hero_image->setAllowedFileCategories('image');
$fields->addFieldToTab('Root.LATEST RELEASE BLOCK', $promo_hero_image);
$fields->addFieldToTab('Root.LATEST RELEASE BLOCK', new TextField ('LatestReleaseVideoDescription', 'Video Description'));
$fields->addFieldToTab('Root.LATEST RELEASE BLOCK', new TextField ('LatestReleaseCurrentButtonText', 'Current Button Text'));
$fields->addFieldToTab('Root.LATEST RELEASE BLOCK', new TextField ('LatestReleaseCurrentButtonLink', 'Current Button Link'));
$fields->addFieldToTab('Root.LATEST RELEASE BLOCK', new TextField ('LatestReleaseUpNextButtonText', 'UpNext Button Text'));
$fields->addFieldToTab('Root.LATEST RELEASE BLOCK', new TextField ('LatestReleaseUpNextButtonLink', 'UpNext Button Link'));
// MARKETPLACE SPOTLIGHT
$config = GridFieldConfig_RelationEditor::create(50);
$config->removeComponentsByType("GridFieldAddNewButton");
$completer = $config->getComponentByType('GridFieldAddExistingAutocompleter');
$completer->setResultsFormat('$Name ($ID)');
$completer->setSearchFields(['Name', 'ID']);
$config->getComponentByType('GridFieldDataColumns')->setDisplayFields
(
[
'ID' => 'ID',
'Name' => 'Name',
]
);
$completer->setSearchList(CompanyService::get()->filter(['Active' => true]));
$services = new GridField('MarketplaceSpotLight',
'Marketplace SpotLight',
$this->MarketplaceSpotLight(), $config);
$fields->addFieldToTab('Root.MARKETPLACE SPOTLIGHT', $services);
// USER STORIES
$userStoryFields = singleton('UserStoryDO')->getCMSFields();
$oldFields = $userStoryFields->toArray();
foreach($oldFields as $field){
$userStoryFields->remove($field);
}
$userStoryFields->add($rootTab = new TabSet("Root", $tabMain = new Tab('Main')));
$homePageImage = new CustomUploadField('HomePageImage', 'Home Page Image');
$homePageImage->setFolderName('homepage');
$homePageImage->setAllowedFileCategories('image');
$userStoryFields->addFieldsToTab('Root.Main', array(
new ReadonlyField('Name', 'Name'),
new TextField('ManyMany[ButtonText]', 'Button Text', ''),
$homePageImage
));
$config = GridFieldConfig_RelationEditor::create(50);
$config->removeComponentsByType("GridFieldAddNewButton");
$config->getComponentByType('GridFieldDetailForm')->setFields($userStoryFields);
$completer = $config->getComponentByType('GridFieldAddExistingAutocompleter');
$completer->setResultsFormat('$Name ($ID)');
$completer->setSearchFields(['Name', 'ID']);
$config->getComponentByType('GridFieldDataColumns')->setDisplayFields
(
[
'ID' => 'ID',
'Name' => 'Name',
]
);
$completer->setSearchList(UserStoryDO::get()->filter(['Active' => true]));
$services = new GridField('UserStories',
'User Stories',
$this->UserStories(), $config);
$fields->addFieldToTab('Root.USER STORIES BLOCK', $services);
// OSF MEMBER SPOTLIGHT
$config = GridFieldConfig_RecordEditor::create(50);
$config->addComponent(new GridFieldAjaxRefresh(1000, false));
$config->removeComponentsByType('GridFieldDeleteAction');
$gridField = new GridField('OSFMembers', 'OSFMembers', $this->OSFMembers(), $config);
$config->getComponentByType("GridFieldDataColumns")->setFieldCasting(array("Description" => "HTMLText->BigSummary"));
$fields->addFieldToTab('Root.OSF MEMBER SPOTLIGHT', $gridField);
return $fields;
}
}
class NewHomePage_Controller extends Page_Controller
{
protected static function getCssIncludes(){
return [
"themes/openstack/css/home-page.css",
"themes/openstack/css/navigation_menu.css",
"themes/openstack/css/dropdown.css",
"themes/openstack/css/announcement-banner.css",
];
}
public function init()
{
parent::init(); // TODO: Change the autogenerated stub
}
}