Skip to content

Allow non hardcoded icons for apps#29013

Merged
PVince81 merged 1 commit intomasterfrom
non-hard-coded-icons
Oct 26, 2017
Merged

Allow non hardcoded icons for apps#29013
PVince81 merged 1 commit intomasterfrom
non-hard-coded-icons

Conversation

@sharidas
Copy link
Contributor

This change helps users to provide their own
custom icons for the apps which work with
ownCloud.

Signed-off-by: Sujith H sharidasan@owncloud.com

Description

This change helps contributors to use non-hardcoded icons. That is every app developer or contributor can now have their own separate icons which can be used with core.

Related Issue

#28751

Motivation and Context

At present the icons are hard coded and are located at core. This prohibits the usage of custom icons for apps. With this change, contributors of apps, can have their own custom app which can be used along with core. No more saving of svg files in the core.

How Has This Been Tested?

I have verified it against 2 apps. One is encryption app ( the change was made in the SettingsManager.php) and another app was firewall app. For the firewall app I modified the AdminSection.php to test.

Screenshots (if appropriate):

settingspagenew

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@sharidas sharidas changed the title Allow non hardcoded icons for apps [WIP] Allow non hardcoded icons for apps Sep 14, 2017
@sharidas sharidas self-assigned this Sep 14, 2017
@sharidas sharidas added this to the development milestone Sep 14, 2017
@@ -53,4 +53,6 @@ public function getPriority();
*/
public function getIconName();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think let's kill the name and just keep the url and we'll make it backwards compatible

'name' => ucfirst($section->getName()),
'active' => $section->getID() === $currentSectionID,
'icon' => $section->getIconName()
'icon' => $section->getIconName(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so we can get rid of this also

$url = strstr($fileAbsolutePath, \OC::$WEBROOT);
return $url;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nooooo more static ;) Why do we need to do this copying stuff?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The intention behind this change was to fetch the data from the web url and download to apps/img folder. Anything wrong?


public function getIconUrl() {
return \OC_App::getIconFromUrl($this->url, $this->getID());
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could use the urlgenerator here, injected in properly

@sharidas sharidas force-pushed the non-hard-coded-icons branch from d8b4dde to 5050bcb Compare September 15, 2017 11:50
@sharidas
Copy link
Contributor Author

Attaching new screenshot for the change made:
newscreenshot

@sharidas sharidas force-pushed the non-hard-coded-icons branch from 5050bcb to d7306ae Compare September 15, 2017 12:08
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can pass in the urlgenerator here - then adjust the constructor to pass it in in \OC\Settings\SettingsManager

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use passed in urlgenerator. Also, the Id is not necessarily the app id so might need some thought here

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we may as well standardise the core icons. So always pass a url. In the controller figure out if its a core icon or not. Then we can remove these crappy css rules for the icons

@sharidas sharidas force-pushed the non-hard-coded-icons branch from d7306ae to 570cb64 Compare September 15, 2017 13:49
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing this one?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

10.0.4

Copy link
Contributor

@tomneedham tomneedham Sep 15, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and we should keep the old method, but add @deprecated from 10.0.4. But this shoudl also be backwards compatible. So inside the section implementation, set $this->url using the url generator - don't need to worry about injection for this backwards compat

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So if we add @deprecated for getIconName in ISection then, I think we will end up having both getIconName and getIconUrl. Because the apps which will be implementing ISection would need to implement both the methods.
So ideally if we don't want to deprecate it, then may be we can have getIconName. And make it app developers responsibility to get the url to be generated and returned from getIconName(), instead of just returning the icon name which it does currently.

@sharidas sharidas force-pushed the non-hard-coded-icons branch from 570cb64 to 8835320 Compare September 15, 2017 14:23
/**
* @since 10.0
* @return string
* @deprecated since 10.0.4
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added @deprecated

@tomneedham
Copy link
Contributor

@PVince81 PVince81 modified the milestones: 10.0.3, development Sep 18, 2017
@sharidas sharidas force-pushed the non-hard-coded-icons branch 2 times, most recently from fff6f2a to 2b5898f Compare September 19, 2017 12:56
* @return string
*/
public function getIconName();
public function getIconUrl();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like this - this will break all existing implementations 👎

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should implement this more in sense where the returned icon name can either be a css class (as done until today) or an image name of the app which hosts the svg.

this way we don't need to change apis and implementation all over the place.

$icon = $section->getIconName();
if (file_exists("$appPath/img/$icon.svg")) {
    $url = $urlGenerator->imagePath("$icon.svg");
    // TODO: add background styling hack
} else {
    // TODO: add icon css class
}

@sharidas sharidas force-pushed the non-hard-coded-icons branch from 2b5898f to b66a621 Compare September 27, 2017 10:10
@sharidas sharidas changed the title [WIP] Allow non hardcoded icons for apps Allow non hardcoded icons for apps Sep 27, 2017
@sharidas sharidas force-pushed the non-hard-coded-icons branch from b66a621 to 5225596 Compare September 27, 2017 10:19
$appPath = \OC_App::getAppPath($section->getID());

if (file_exists($appPath . '/img/' . $icon)) {
$icon = \OC::$server->getURLGenerator()->imagePath($section->getID(), $icon);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The URLGenerator should be injected in the constructor

// Iterate through sections and get id, name and see if currently active
foreach($sections as $section) {

$icon = $section->getIconName() . '.svg';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this "getIcon" code to another function and call it here. This logic should be probably out of this class so we can unittest it properly. If there is no place for this, it should be fine to create a private function here in the short term.

In addition, I think there is already a function to retrieve icons for apps (I might be wrong) Any reason to not use it?

In the phpdoc of the new function (whenever is placed) include how the function should behave. Right now I'm not sure what is the expected behaviour if several icons are provided: if I want to use "marvellous_icon.png", why I'm checking "marvellous_icon.png.svg"?
If only .svg files are supported, make sure this is known, including in the comments of the function.
Since I have no idea what is the expected behaviour here, I'm more inclined to think the current behaviour is buggy.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of extra things:

  • Unless the icon name is already sanitized, make sure it doesn't contain /../ or something similar
  • I'm not sure what is the "default" expectation: I guess it should be using the filename without extension as icon name (which is fine). In any case, optimize for this default case. If the default is to include the extension you'd be checking for a missing file constantly. Just something to take care of.

<?php foreach($_['personalNav'] as $item) {
$active = $item['active'] ? ' active ' : '';

$ocUrlorIcon = \OCP\Util::sanitizeHTML($item['icon']);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be a good time to rewrite this piece to just use this as a template and avoid adding logic here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Can we do this as a separate PR?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really mind, but there will be conflicts with this PR if t isn't merged soon because that code will depend on this branch... @tomneedham @DeepDiver1975 opinions?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do it in here - own commit for now to see the diff ... later we squash

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved the logic from here to https://github.com/owncloud/core/pull/29013/files#diff-3393e43384d070ab12865348f9279030R123. I hope this makes sense now.

@sharidas sharidas force-pushed the non-hard-coded-icons branch 2 times, most recently from b2d04f0 to 204fff3 Compare October 6, 2017 11:52
@jvillafanez
Copy link
Member

The rewrite I had in mind was more like:

<li class="divider"><?php p($l->t('Personal')); ?></li>
<?php foreach($_['personalNav'] as $item): ?>
<li>
  <?php if ($item['active']): ?>
    <?php if ($item['iconIsUrl]): ?>
      <a class="svg active" style="background-image: url(<?php p($item['icon']) ?>)" href='<?php p($item['link']); ?>'><?php p($item['name']) ?></a>
    <?php else: ?>
      <a class="svg active icon-<?php p($item['icon']) ?>)" href='<?php p($item['link']); ?>'><?php p($item['name']) ?></a>
    <?php endif; ?>
  <?php else: ?>
    <?php if ($item['iconIsUrl]): ?>
      <a class="svg" style="background-image: url(<?php p($item['icon']) ?>)" href='<?php p($item['link']); ?>'><?php p($item['name']) ?></a>
    <?php else: ?>
      <a class="svg icon-<?php p($item['icon']) ?>)" href='<?php p($item['link']); ?>'><?php p($item['name']) ?></a>
  <?php endif; ?>
</li>
<?php endforeach; ?>

Maybe we can make it smaller injecting "active" or an empty string instead of checking if the $item['active'] is a boolean or not, but as you see, the template just output information with the minimum control structures.

@sharidas sharidas force-pushed the non-hard-coded-icons branch from 204fff3 to b85a585 Compare October 6, 2017 15:02
@sharidas
Copy link
Contributor Author

sharidas commented Oct 6, 2017

@jvillafanez I have updated the change let me know if this ok.

@sharidas sharidas force-pushed the non-hard-coded-icons branch from b85a585 to d40e54d Compare October 9, 2017 06:26
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

\OCP\Util::sanitizeHTML(...) isn't needed with the p function

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the call to sanitizeHTML

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indentation here seems misplaced

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@sharidas sharidas force-pushed the non-hard-coded-icons branch from d40e54d to 28f74bd Compare October 9, 2017 06:55
@sharidas
Copy link
Contributor Author

sharidas commented Oct 9, 2017

@jvillafanez Corrected indentation and removed call to \OCP\Util::sanitizeHTML() inside p()

Copy link
Member

@jvillafanez jvillafanez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good to me, not tested.

@sharidas
Copy link
Contributor Author

sharidas commented Oct 9, 2017

Tested the code by replacing icon password with docker. I copied docker.svg from https://worldvectorlogo.com/download/docker.svg and the settings page looks like this:
changeencryptionicon
And when the change is reverted back to password at https://github.com/owncloud/core/blob/master/lib/private/Settings/SettingsManager.php#L204 the settings page encryption icon looks like this:
changeencryptionicon_old

@codecov
Copy link

codecov bot commented Oct 20, 2017

Codecov Report

Merging #29013 into master will increase coverage by 0.01%.
The diff coverage is 61.53%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master   #29013      +/-   ##
============================================
+ Coverage     60.21%   60.23%   +0.01%     
- Complexity    17182    17184       +2     
============================================
  Files          1030     1030              
  Lines         57271    57263       -8     
============================================
+ Hits          34485    34491       +6     
+ Misses        22786    22772      -14
Impacted Files Coverage Δ Complexity Δ
lib/private/Settings/SettingsManager.php 72.72% <ø> (-0.18%) 44 <0> (ø)
settings/templates/settingsPage.php 0% <0%> (ø) 0 <0> (ø) ⬇️
settings/Controller/SettingsPageController.php 70.68% <88.88%> (+2.68%) 14 <2> (+2) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e8d5f70...cdd2692. Read the comment docs.

This change helps users to provide their own
custom icons for the apps which work with
ownCloud.

Signed-off-by: Sujith H <sharidasan@owncloud.com>
@sharidas sharidas force-pushed the non-hard-coded-icons branch from 0e0d71e to cdd2692 Compare October 26, 2017 02:59
new Section('workflow', $this->l->t('Workflows & Tags'), 85, 'workflows'),
new Section('sharing', $this->l->t('Sharing'), 80, 'share'),
new Section('search', $this->l->t('Search'), 75, 'search'),
new Section('updates', $this->l->t('Updates'), 20, 'update'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why remove this ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While searching for update.svg, I couldn't find at core. That made me remove this line. I can revert back the change, if my finding was wrong.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the explanation, I just wanted to double check that this wasn't a mistake. Let's keep it.

@PVince81 PVince81 merged commit 2a6594d into master Oct 26, 2017
@PVince81 PVince81 deleted the non-hard-coded-icons branch October 26, 2017 09:20
@PVince81
Copy link
Contributor

@sharidas please backport

@sharidas
Copy link
Contributor Author

Created backport PR: #29358

@lock
Copy link

lock bot commented Aug 2, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Aug 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants