-
-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Public interfaces for dashboard app #10222
Conversation
@@ -0,0 +1,53 @@ | |||
<?php | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Licence header
/** | ||
* @return string | ||
*/ | ||
public function getId(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NC14 is >php 7.0. So you can use return types
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can I use : void ? (php 7.1)
@@ -0,0 +1,53 @@ | |||
<?php |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
strict typing since we are >7.0 anyway
@rullzer: please have a look to the asked edit |
* | ||
* @param string $widgetId | ||
*/ | ||
public function __construct(string $widgetId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't add the constructor to the interfaces.
Just call setWidgetId
instead
@daita You will also need to adjust the following xsd files to make the dashboard section valid in the appinfo.xml: https://github.com/nextcloud/server/blob/master/resources/app-info-shipped.xsd And the app store needs those updates as well. |
Just a general thing, when we add new sections to the appinfo.xml like for this case, does this break apps that also support versions previous to 14? The app store only has one version-independent file to validate the appinfo, so that should work fine, but does the server also checks for a valid appinfo at some point? |
Yes the app check-code checks it, but additional stuff is not a problem as far as I know. |
interface IDashboardWidget { | ||
|
||
/** | ||
* @return string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing @since 14.0.0
on the methods and the interface.
@@ -0,0 +1,79 @@ | |||
<?php declare(strict_types=1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put the declare()
on a new line.
It's a bit late for that ... freeze was on Friday ... at least for the server PR. And also it was never brought up to be needed for 14. :/ |
No need to rush in the dashboard, no? We can merge it very early for 15, and then properly work on adding endpoints to the different apps and have the Dashboard app use those, like any other app. |
Well, you know. After working on something else for months and finally having few days to do something fun. But I get it; @nickvergessen already told me last week that I should not waste my time on it. So, no rush. |
So, ready for NC15. @nickvergessen : Added also a IDashboardManager that can be called with Automatic DI so there is no more API, just call the right method from the dashboardManager, that will check if app is installed or not. |
* @throws DashboardAppNotAvailableException | ||
*/ | ||
public function createGlobalEvent(string $widgetId, array $payload, string $uniqueId = '' | ||
) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
opsy
maxOccurs="unbounded"/> | ||
maxOccurs="unbounded"/> | ||
</xs:sequence> | ||
</xs:complexType> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this needs to go to the appstore too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More general why is this needed here? I don't see it being used yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some nitpicks. Please also make sure you have a line break at the end of each file (as github shows here) to be consistent with our other source files.
Thanks!
/** | ||
* @since 15.0.0 | ||
* | ||
* @return array |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add more documentation to these methods. What are they supposed to return? array
is very generic 😉
/** | ||
* @since 15.0.0 | ||
* | ||
* @return array |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above
* | ||
* @param string $widgetId | ||
*/ | ||
public function __construct(string $widgetId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the interface determines the constructor interface? This doesn't seem right 🙈
/** | ||
* @since 15.0.0 | ||
* | ||
* @param string $request |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what kind of request is this string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@daita 🏓
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤷♂️ 🏓
* @param string $userId | ||
* @param string $widgetId | ||
*/ | ||
public function __construct(string $widgetId, string $userId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove this. Same issue as above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@daita 🏓
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
saw that ... removed.
resources/app-info.xsd
Outdated
<xs:sequence> | ||
<xs:element name="widget" type="php-class" minOccurs="1" | ||
maxOccurs="unbounded"/> | ||
maxOccurs="unbounded"/> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that doesn't look right.
resources/app-info-shipped.xsd
Outdated
<xs:sequence> | ||
<xs:element name="widget" type="php-class" minOccurs="1" | ||
maxOccurs="unbounded"/> | ||
maxOccurs="unbounded"/> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
} | ||
|
||
try { | ||
return \OC::$server->query($service); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can inject IServerContainer
in your constructor. Then you can also better unit test this.
🏓 Would be great to go on with this one, as it is a blocker to work on the dev of widgets for 15. |
* 'content' => (string) path to the HTML Template of the widget, | ||
* 'function' => (string) JavaScript function to be called when | ||
* loading the widget on the dashboard | ||
* ]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A template object would be nice, because it is automatically properly typed and has then proper autocompletion as well. 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved to objects in various spot, pushed. Will comment during the day.
* ] | ||
* | ||
* 'push' contains the JS function to be called on push event: | ||
* 'push' => (string) JavaScript function to be called on push event |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A settings object would be nice instead of a multidimensional array. 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Beside the comments it looks good 👍
This comment has been minimized.
This comment has been minimized.
*/ | ||
public function getWidgetConfig(string $widgetId, string $userId): IWidgetConfig { | ||
/** @var \OCA\Dashboard\Service\WidgetsService $widgetsService */ | ||
$widgetsService = $this->getService('\OCA\Dashboard\Service\WidgetsService'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use the ::class
syntax, this makes finding class usages and refactoring later a lot easier 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would require another try-catch in here of course, in case the dashboard app is not here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why would it? ::class
is simply replaced by the FQCN (string) by the interpreter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought this would invoke autoloading and therefor throw? 🤷
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The thing is that I am not sure the app is available at this point, and calling the ::class does not clean enough
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$ php -a
Interactive shell
php > echo Joas::class;
Joas
*/ | ||
public function createUsersEvent(string $widgetId, array $users, array $payload, string $uniqueId = '') { | ||
/** @var \OCA\Dashboard\Service\EventsService $eventsService */ | ||
$eventsService = $this->getService('\OCA\Dashboard\Service\EventsService'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
*/ | ||
public function createGroupsEvent(string $widgetId, array $groups, array $payload, string $uniqueId = '') { | ||
/** @var \OCA\Dashboard\Service\EventsService $eventsService */ | ||
$eventsService = $this->getService('\OCA\Dashboard\Service\EventsService'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
*/ | ||
public function createGlobalEvent(string $widgetId, array $payload, string $uniqueId = '') { | ||
/** @var \OCA\Dashboard\Service\EventsService $eventsService */ | ||
$eventsService = $this->getService('\OCA\Dashboard\Service\EventsService'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
/** | ||
* @since 15.0.0 | ||
* | ||
* @param string $request |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤷♂️ 🏓
public function getInitFunction(): string; | ||
|
||
/** | ||
* JavaScript function to be called when loading the widget on the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how will that function be invoked? Does it have to exist globally?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it does not have to exist globally, it is called by the app
* | ||
* @return array | ||
*/ | ||
public function getCss(): array { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how will this CSS be loaded? Is this property the actual CSS contents or just the URL?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see a reason for much of this implementation to be in the server. Like the actual implementation of a lot of those classes can just be in the dashboard app itself right?
* | ||
* @param string $type | ||
*/ | ||
public function __construct($type = '') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typehint
maxOccurs="unbounded"/> | ||
maxOccurs="unbounded"/> | ||
</xs:sequence> | ||
</xs:complexType> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More general why is this needed here? I don't see it being used yet.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks a lot better 👍
Let's move the implementations to the dashboard app. I don't think they should be in the server as they aren't even used directly.
Nitpick: @see WidgetSetting
is a bit misleading. Not sure what it should tell me. It's also a bit misplaced in the interfaces because that would point to the private implementation. All usage should be documented in the public interfaces though 😉
* | ||
* @package OC\Dashboard\Model | ||
*/ | ||
class WidgetSetting implements JsonSerializable { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this implementation can be safely move to the dashboard app
* | ||
* @package OC\Dashboard\Model | ||
*/ | ||
class WidgetSetup implements JsonSerializable { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this implementation can be safely move to the dashboard app
* | ||
* @package OC\Dashboard\Model | ||
*/ | ||
class WidgetTemplate implements JsonSerializable { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this implementation can be safely move to the dashboard app
|
WidgetSettings is not used outside the private namespace. Hence it must not be used by apps.
|
If a construct (class/interface) is used by an app, it has to be a public API. There are
|
After a bit of discussion I think I've finally understood how the different components will be used. I created a little diagram that outlines where certain classes/interfaces live: This works for @daita and clearly separates what should be in server/dashboard and other apps. This removes and dependency from server on the dashboard app. The implementation part in server (esp the private part) is minimal. The three classes for setup, settings and template were deliberately moved to OCP as classes as they are simple models (or better data transfer objects). |
Yes makes sense. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok I think it is time to get this in.
It looks sane to me.
Lets see how far we get.
@daita could you squash your commits?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wasn't the plan to have WidgetSettings
, WidgetSetup
and WidgetTemplate
in OCP? They're in the private namespace right now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good now!
You probably have to run ./build/autoloaderchecker.sh
to make CI happy.
Also, please make squash this and make this a single commit change 😉
3689505
to
323c330
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove additional files and rerun autoloader command
'OCP\\Dashboard\\IDashboardManager' => $baseDir . '/lib/public/Dashboard/IDashboardManager.php', | ||
'OCP\\Dashboard\\IDashboardWidget' => $baseDir . '/lib/public/Dashboard/IDashboardWidget.php', | ||
'OCP\\Dashboard\\Model\\IWidgetConfig' => $baseDir . '/lib/public/Dashboard/Model/IWidgetConfig.php', | ||
'OCP\\Dashboard\\Model\\IWidgetRequest' => $baseDir . '/lib/public/Dashboard/Model/IWidgetRequest.php', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
interfaces were removed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nvm the last review, I was confused by the interface names it seems
0880b33
to
b98fa11
Compare
Signed-off-by: Maxence Lange <maxence@artificial-owl.com> Merge remote-tracking branch 'origin/interface-dashboard' into interface-dashboard Signed-off-by: Maxence Lange <maxence@artificial-owl.com> moving data object to OCP Signed-off-by: Maxence Lange <maxence@artificial-owl.com> update autoload files Signed-off-by: Maxence Lange <maxence@artificial-owl.com> +@SInCE Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
b98fa11
to
dfd4782
Compare
No description provided.