forked from phacility/phabricator
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathPhabricatorCountdownViewController.php
133 lines (105 loc) · 3.43 KB
/
PhabricatorCountdownViewController.php
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
<?php
final class PhabricatorCountdownViewController
extends PhabricatorCountdownController {
public function shouldAllowPublic() {
return true;
}
public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$id = $request->getURIData('id');
$countdown = id(new PhabricatorCountdownQuery())
->setViewer($viewer)
->withIDs(array($id))
->executeOne();
if (!$countdown) {
return new Aphront404Response();
}
$countdown_view = id(new PhabricatorCountdownView())
->setUser($viewer)
->setCountdown($countdown);
$id = $countdown->getID();
$title = $countdown->getTitle();
$crumbs = $this
->buildApplicationCrumbs()
->addTextCrumb($countdown->getMonogram())
->setBorder(true);
$epoch = $countdown->getEpoch();
if ($epoch >= PhabricatorTime::getNow()) {
$icon = 'fa-clock-o';
$color = '';
$status = pht('Running');
} else {
$icon = 'fa-check-square-o';
$color = 'dark';
$status = pht('Launched');
}
$header = id(new PHUIHeaderView())
->setHeader($title)
->setUser($viewer)
->setPolicyObject($countdown)
->setStatus($icon, $color, $status)
->setHeaderIcon('fa-rocket');
$curtain = $this->buildCurtain($countdown);
$subheader = $this->buildSubheaderView($countdown);
$timeline = $this->buildTransactionTimeline(
$countdown,
new PhabricatorCountdownTransactionQuery());
$comment_view = id(new PhabricatorCountdownEditEngine())
->setViewer($viewer)
->buildEditEngineCommentView($countdown);
$content = array(
$countdown_view,
$timeline,
$comment_view,
);
$view = id(new PHUITwoColumnView())
->setHeader($header)
->setSubheader($subheader)
->setCurtain($curtain)
->setMainColumn($content);
return $this->newPage()
->setTitle($title)
->setCrumbs($crumbs)
->setPageObjectPHIDs(
array(
$countdown->getPHID(),
))
->appendChild($view);
}
private function buildCurtain(PhabricatorCountdown $countdown) {
$viewer = $this->getViewer();
$id = $countdown->getID();
$can_edit = PhabricatorPolicyFilter::hasCapability(
$viewer,
$countdown,
PhabricatorPolicyCapability::CAN_EDIT);
$curtain = $this->newCurtainView($countdown);
$curtain->addAction(
id(new PhabricatorActionView())
->setIcon('fa-pencil')
->setName(pht('Edit Countdown'))
->setHref($this->getApplicationURI("edit/{$id}/"))
->setDisabled(!$can_edit)
->setWorkflow(!$can_edit));
return $curtain;
}
private function buildSubheaderView(
PhabricatorCountdown $countdown) {
$viewer = $this->getViewer();
$author = $viewer->renderHandle($countdown->getAuthorPHID())->render();
$date = phabricator_datetime($countdown->getDateCreated(), $viewer);
$author = phutil_tag('strong', array(), $author);
$person = id(new PhabricatorPeopleQuery())
->setViewer($viewer)
->withPHIDs(array($countdown->getAuthorPHID()))
->needProfileImage(true)
->executeOne();
$image_uri = $person->getProfileImageURI();
$image_href = '/p/'.$person->getUsername();
$content = pht('Authored by %s on %s.', $author, $date);
return id(new PHUIHeadThingView())
->setImage($image_uri)
->setImageHref($image_href)
->setContent($content);
}
}