forked from phacility/phabricator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPhabricatorPhurlURLViewController.php
154 lines (123 loc) · 3.98 KB
/
PhabricatorPhurlURLViewController.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<?php
final class PhabricatorPhurlURLViewController
extends PhabricatorPhurlController {
public function shouldAllowPublic() {
return true;
}
public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$id = $request->getURIData('id');
$timeline = null;
$url = id(new PhabricatorPhurlURLQuery())
->setViewer($viewer)
->withIDs(array($id))
->executeOne();
if (!$url) {
return new Aphront404Response();
}
$title = $url->getMonogram();
$page_title = $title.' '.$url->getName();
$crumbs = $this->buildApplicationCrumbs();
$crumbs->addTextCrumb($title);
$crumbs->setBorder(true);
$timeline = $this->buildTransactionTimeline(
$url,
new PhabricatorPhurlURLTransactionQuery());
$timeline->setQuoteRef($url->getMonogram());
$header = $this->buildHeaderView($url);
$curtain = $this->buildCurtain($url);
$details = $this->buildPropertySectionView($url);
$url_error = id(new PHUIInfoView())
->setErrors(array(pht('This URL is invalid due to a bad protocol.')))
->setIsHidden($url->isValid());
$add_comment_form = $this->buildCommentForm($url, $timeline);
$view = id(new PHUITwoColumnView())
->setHeader($header)
->setCurtain($curtain)
->setMainColumn(array(
$url_error,
$details,
$timeline,
$add_comment_form,
));
return $this->newPage()
->setTitle($page_title)
->setCrumbs($crumbs)
->setPageObjectPHIDs(array($url->getPHID()))
->appendChild(
array(
$view,
));
}
private function buildCommentForm(PhabricatorPhurlURL $url, $timeline) {
$viewer = $this->getViewer();
$box = id(new PhabricatorPhurlURLEditEngine())
->setViewer($viewer)
->buildEditEngineCommentView($url)
->setTransactionTimeline($timeline);
return $box;
}
private function buildHeaderView(PhabricatorPhurlURL $url) {
$viewer = $this->getViewer();
$icon = 'fa-check';
$color = 'bluegrey';
$status = pht('Active');
$id = $url->getID();
$visit = id(new PHUIButtonView())
->setTag('a')
->setText(pht('Visit URL'))
->setIcon('fa-external-link')
->setHref($url->getRedirectURI())
->setDisabled(!$url->isValid());
$header = id(new PHUIHeaderView())
->setUser($viewer)
->setHeader($url->getDisplayName())
->setStatus($icon, $color, $status)
->setPolicyObject($url)
->setHeaderIcon('fa-compress')
->addActionLink($visit);
return $header;
}
private function buildCurtain(PhabricatorPhurlURL $url) {
$viewer = $this->getViewer();
$id = $url->getID();
$curtain = $this->newCurtainView($url);
$can_edit = PhabricatorPolicyFilter::hasCapability(
$viewer,
$url,
PhabricatorPolicyCapability::CAN_EDIT);
$curtain
->addAction(
id(new PhabricatorActionView())
->setName(pht('Edit Phurl'))
->setIcon('fa-pencil')
->setHref($this->getApplicationURI("url/edit/{$id}/"))
->setDisabled(!$can_edit)
->setWorkflow(!$can_edit));
return $curtain;
}
private function buildPropertySectionView(PhabricatorPhurlURL $url) {
$viewer = $this->getViewer();
$properties = id(new PHUIPropertyListView())
->setUser($viewer);
$properties->addProperty(
pht('Short URL'),
$url->getRedirectURI());
$properties->addProperty(
pht('Original URL'),
$url->getLongURL());
$properties->addProperty(
pht('Alias'),
$url->getAlias());
$description = $url->getDescription();
if (strlen($description)) {
$description = new PHUIRemarkupView($viewer, $description);
$properties->addSectionHeader(pht('Description'));
$properties->addTextContent($description);
}
return id(new PHUIObjectBoxView())
->setHeaderText(pht('Details'))
->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)
->appendChild($properties);
}
}