Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F102658672
PhabricatorHomePreferencesSettingsPanel.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sat, Feb 22, 23:14
Size
6 KB
Mime Type
text/x-php
Expires
Mon, Feb 24, 23:14 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
24384369
Attached To
rPH Phabricator
PhabricatorHomePreferencesSettingsPanel.php
View Options
<?php
final
class
PhabricatorHomePreferencesSettingsPanel
extends
PhabricatorSettingsPanel
{
public
function
getPanelKey
()
{
return
'home'
;
}
public
function
getPanelName
()
{
return
pht
(
'Home Page'
);
}
public
function
getPanelGroupKey
()
{
return
PhabricatorSettingsApplicationsPanelGroup
::
PANELGROUPKEY
;
}
public
function
processRequest
(
AphrontRequest
$request
)
{
$viewer
=
$this
->
getViewer
();
$preferences
=
$this
->
loadTargetPreferences
();
$pinned_key
=
PhabricatorPinnedApplicationsSetting
::
SETTINGKEY
;
$pinned
=
$preferences
->
getSettingValue
(
$pinned_key
);
$apps
=
id
(
new
PhabricatorApplicationQuery
())
->
setViewer
(
$viewer
)
->
withInstalled
(
true
)
->
withUnlisted
(
false
)
->
withLaunchable
(
true
)
->
execute
();
$app_list
=
array
();
foreach
(
$pinned
as
$app
)
{
if
(
isset
(
$apps
[
$app
]))
{
$app_list
[
$app
]
=
$apps
[
$app
];
}
}
if
(
$request
->
getBool
(
'reset'
))
{
if
(
$request
->
isFormPost
())
{
$this
->
writePinnedApplications
(
$preferences
,
null
);
return
id
(
new
AphrontRedirectResponse
())
->
setURI
(
$this
->
getPanelURI
());
}
return
$this
->
newDialog
()
->
setTitle
(
pht
(
'Reset Applications'
))
->
addHiddenInput
(
'reset'
,
'true'
)
->
appendParagraph
(
pht
(
'Reset pinned applications to their defaults?'
))
->
addSubmitButton
(
pht
(
'Reset Applications'
))
->
addCancelButton
(
$this
->
getPanelURI
());
}
if
(
$request
->
getBool
(
'add'
))
{
$options
=
array
();
foreach
(
$apps
as
$app
)
{
$options
[
get_class
(
$app
)]
=
$app
->
getName
();
}
asort
(
$options
);
unset
(
$options
[
'PhabricatorApplicationsApplication'
]);
if
(
$request
->
isFormPost
())
{
$pin
=
$request
->
getStr
(
'pin'
);
if
(
isset
(
$options
[
$pin
])
&&
!
in_array
(
$pin
,
$pinned
))
{
$pinned
[]
=
$pin
;
$this
->
writePinnedApplications
(
$preferences
,
$pinned
);
return
id
(
new
AphrontRedirectResponse
())
->
setURI
(
$this
->
getPanelURI
());
}
}
$options_control
=
id
(
new
AphrontFormSelectControl
())
->
setName
(
'pin'
)
->
setLabel
(
pht
(
'Application'
))
->
setOptions
(
$options
)
->
setDisabledOptions
(
array_keys
(
$app_list
));
$form
=
id
(
new
AphrontFormView
())
->
setViewer
(
$viewer
)
->
addHiddenInput
(
'add'
,
'true'
)
->
appendRemarkupInstructions
(
pht
(
'Choose an application to pin to your home page.'
))
->
appendChild
(
$options_control
);
return
$this
->
newDialog
()
->
setWidth
(
AphrontDialogView
::
WIDTH_FORM
)
->
setTitle
(
pht
(
'Pin Application'
))
->
appendChild
(
$form
->
buildLayoutView
())
->
addSubmitButton
(
pht
(
'Pin Application'
))
->
addCancelButton
(
$this
->
getPanelURI
());
}
$unpin
=
$request
->
getStr
(
'unpin'
);
if
(
$unpin
)
{
$app
=
idx
(
$apps
,
$unpin
);
if
(
$app
)
{
if
(
$request
->
isFormPost
())
{
$pinned
=
array_diff
(
$pinned
,
array
(
$unpin
));
$this
->
writePinnedApplications
(
$preferences
,
$pinned
);
return
id
(
new
AphrontRedirectResponse
())
->
setURI
(
$this
->
getPanelURI
());
}
return
$this
->
newDialog
()
->
setTitle
(
pht
(
'Unpin Application'
))
->
addHiddenInput
(
'unpin'
,
$unpin
)
->
appendParagraph
(
pht
(
'Unpin the %s application from your home page?'
,
phutil_tag
(
'strong'
,
array
(),
$app
->
getName
())))
->
addSubmitButton
(
pht
(
'Unpin Application'
))
->
addCancelButton
(
$this
->
getPanelURI
());
}
}
$order
=
$request
->
getStrList
(
'order'
);
if
(
$order
&&
$request
->
validateCSRF
())
{
$this
->
writePinnedApplications
(
$preferences
,
$order
);
return
id
(
new
AphrontRedirectResponse
())
->
setURI
(
$this
->
getPanelURI
());
}
$list_id
=
celerity_generate_unique_node_id
();
$list
=
id
(
new
PHUIObjectItemListView
())
->
setViewer
(
$viewer
)
->
setID
(
$list_id
);
Javelin
::
initBehavior
(
'reorder-applications'
,
array
(
'listID'
=>
$list_id
,
'panelURI'
=>
$this
->
getPanelURI
(),
));
foreach
(
$app_list
as
$key
=>
$application
)
{
if
(
$key
==
'PhabricatorApplicationsApplication'
)
{
continue
;
}
$icon
=
$application
->
getIcon
();
if
(!
$icon
)
{
$icon
=
'application'
;
}
$icon_view
=
javelin_tag
(
'span'
,
array
(
'class'
=>
'phui-icon-view phui-font-fa '
.
$icon
,
'aural'
=>
false
,
),
''
);
$item
=
id
(
new
PHUIObjectItemView
())
->
setHeader
(
$application
->
getName
())
->
setImageIcon
(
$icon_view
)
->
addAttribute
(
$application
->
getShortDescription
())
->
setGrippable
(
true
);
$item
->
addAction
(
id
(
new
PHUIListItemView
())
->
setIcon
(
'fa-times'
)
->
setHref
(
$this
->
getPanelURI
().
'?unpin='
.
$key
)
->
setWorkflow
(
true
));
$item
->
addSigil
(
'pinned-application'
);
$item
->
setMetadata
(
array
(
'applicationClass'
=>
$key
,
));
$list
->
addItem
(
$item
);
}
$header
=
id
(
new
PHUIHeaderView
())
->
setHeader
(
pht
(
'Pinned Applications'
))
->
addActionLink
(
id
(
new
PHUIButtonView
())
->
setTag
(
'a'
)
->
setText
(
pht
(
'Pin Application'
))
->
setHref
(
$this
->
getPanelURI
().
'?add=true'
)
->
setWorkflow
(
true
)
->
setIcon
(
'fa-thumb-tack'
))
->
addActionLink
(
id
(
new
PHUIButtonView
())
->
setTag
(
'a'
)
->
setText
(
pht
(
'Reset to Defaults'
))
->
setHref
(
$this
->
getPanelURI
().
'?reset=true'
)
->
setWorkflow
(
true
)
->
setIcon
(
'fa-recycle'
));
$box
=
id
(
new
PHUIObjectBoxView
())
->
setHeader
(
$header
)
->
setObjectList
(
$list
);
return
$box
;
}
private
function
writePinnedApplications
(
PhabricatorUserPreferences
$preferences
,
$pinned
)
{
$viewer
=
$this
->
getViewer
();
$request
=
$this
->
getController
()->
getRequest
();
$pinned_key
=
PhabricatorPinnedApplicationsSetting
::
SETTINGKEY
;
$editor
=
id
(
new
PhabricatorUserPreferencesEditor
())
->
setActor
(
$viewer
)
->
setContentSourceFromRequest
(
$request
)
->
setContinueOnNoEffect
(
true
)
->
setContinueOnMissingFields
(
true
);
$xactions
=
array
();
$xactions
[]
=
$preferences
->
newTransaction
(
$pinned_key
,
$pinned
);
$editor
->
applyTransactions
(
$preferences
,
$xactions
);
}
}
Event Timeline
Log In to Comment