Skip to content
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

Improve js client #931

Merged
merged 6 commits into from
Jun 15, 2017
Merged

Improve js client #931

merged 6 commits into from
Jun 15, 2017

Conversation

niol
Copy link
Collaborator

@niol niol commented May 12, 2017

Some minor enhancements and refactoring, use API for login and update item datetimes client-side.

@@ -1,6 +1,154 @@
/**
* db functions: client data repository
*/


selfoss.dbOnline = {
Copy link
Member

Choose a reason for hiding this comment

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

I do not understand the name. Under database, I usually imagine something that stores data.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Here it fetches data. I'm open to other propositions.

Copy link
Member

Choose a reason for hiding this comment

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

Was there any particular motivation for moving it into a separate file?

The main issue I have with this is probably the entangledness of the architecture, though refactoring it is a long term goal.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It makes the base file a little less long and makes sense regarding my work in https://github.com/niol/selfoss/blob/ppr/offline/public/js/selfoss-db.js

Copy link
Member

Choose a reason for hiding this comment

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

As I see it, these three objects form the model layer. Optimally, the dbOnline object should only take care of fetching/uploading data from the server. It could then be called synchronizer. The dbOffline should only be a nice wrapper above dexie, I would call it storage. Last, the db object could be an envelope above synchronizer and storage, providing an opaque model for the rest of the app. What I find the most important, none of the object should have any access to DOM.

Copy link
Member

Choose a reason for hiding this comment

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

I am not really convinced the whole functions should be moved here. I would only move the promise of AJAX request and keep the rest in selfoss-base. In future, the promise would also internally handle the database but the DOM manipulation does not really fit here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Okay then you can rebase this patch out later.

}

if ($error !== null) {
$view->jsonSuccess([
Copy link
Member

Choose a reason for hiding this comment

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

Why do we use jsonSuccess instead of jsonError?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It made not much sense but the login API was like that before so I did ont change et.

Copy link
Member

Choose a reason for hiding this comment

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

Okay, I will take care of this in the refactoring pull request.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

jsonError adds a 400 Bad Request error. If password or username are missing, it is a bad request, so you are right, I'll fix this. This is not the case for the auth error.

@@ -4,6 +4,60 @@
selfoss.ui = {


showLogin: function(error) {
var error = (typeof error !== 'undefined') ? error : '';
Copy link
Member

Choose a reason for hiding this comment

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

Maybe taking care of this in css would be simpler:

#nav-refresh, … {
    display: none;
}
body.publicmode #nav-refresh, body.loggedin #nav-refresh, … {
    display: block;
}

@@ -75,7 +90,9 @@ var selfoss = {
window.setInterval(selfoss.dbOnline.sync, 60*1000);

window.setInterval(selfoss.ui.refreshEntryDatetimes, 60*1000);
});

selfoss.ui.showMainUi();
Copy link
Member

Choose a reason for hiding this comment

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

The UI should be shown before the events are initialised otherwise events.resize will be fired prematurely and the custom scroll bar will be calculated incorrectly:

Copy link
Member

Choose a reason for hiding this comment

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

I can still reproduce this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I cannot manage to reproduce. Can you please describe the steps?

Copy link
Member

Choose a reason for hiding this comment

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

After you log in it seems to work fine but if you refresh the page, it overflows. You need to have enough tags or items to fill the whole area, or resize the window before reloading the page. I can reproduce it in both Firefox and Chomium.

@@ -75,7 +90,9 @@ var selfoss = {
window.setInterval(selfoss.dbOnline.sync, 60*1000);

window.setInterval(selfoss.ui.refreshEntryDatetimes, 60*1000);
});

selfoss.ui.showMainUi();
Copy link
Member

Choose a reason for hiding this comment

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

I can still reproduce this.

type: 'GET',
dataType: 'json',
data: {
since: selfoss.db.lastUpdate.toISOString(),
Copy link
Member

Choose a reason for hiding this comment

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

I am getting TypeError: selfoss.db.lastUpdate is undefined here.

@@ -52,7 +52,7 @@
</head>
<body class="
<?= $this->publicMode === true ? 'publicmode' : ''; ?>
<?= $this->loggedin === true ? 'loggedin' : 'notloggedin'; ?>
<?= $this->authEnabled === true ? 'auth' : ''; ?>
Copy link
Member

Choose a reason for hiding this comment

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

I am still getting the auth form even when the authentication is disabled.

}

#loginform.loading {
background: url('images/fancybox_loading.gif') center center no-repeat;
Copy link
Member

Choose a reason for hiding this comment

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

Why use fancybox’s loading animation instead of the selfoss one from #content.loading?

*
* @return string
*/
public function tagsAddColors($itemTags, $tags = null) {
Copy link
Member

Choose a reason for hiding this comment

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

Could you document the arguments?

*
* @return array tag color array
*/
private function getTagsWithColors($tags) {
Copy link
Member

Choose a reason for hiding this comment

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

Could you add array type hint?



hasSession: function() {
selfoss.loggedin = Cookies.get('onlineSession') == 'true';
Copy link
Member

Choose a reason for hiding this comment

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

What about when PHP session expires (simulated by deleting the PHPSESSID cookie).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This cookie is a hint that there was an online session when last loaded, and will be removed at startup when PHPSESSID is cleared. When that PHPSESSID is cleared, you get like before the 403 error after each ajax request. The next step is to fix #919 .



logout: function() {
selfoss.clearSession();
Copy link
Member

Choose a reason for hiding this comment

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

Maybe this should be done only after the user was logged out, to make the deauthentication errors more visible.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Again, this is all done with offline in mind and is only a hint that there was an online session last time.

@@ -1,6 +1,154 @@
/**
* db functions: client data repository
*/


selfoss.dbOnline = {
Copy link
Member

Choose a reason for hiding this comment

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

I am not really convinced the whole functions should be moved here. I would only move the promise of AJAX request and keep the rest in selfoss-base. In future, the promise would also internally handle the database but the DOM manipulation does not really fit here.

*
* @return void
*/
sync: function(force) {
Copy link
Member

Choose a reason for hiding this comment

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

Same for this function.

<li id="nav-filter-unread" class="nav-filter-unread" role="link" tabindex="0"><?= \F3::get('lang_unread')?> <span class="unread-count"></span></li>
<li id="nav-filter-starred" class="nav-filter-starred" role="link" tabindex="0"><?= \F3::get('lang_starred') ?> <span></span></li>
<div id="loginform">
<form action="<?= $this->base; ?>?login=1" method="post">
Copy link
Member

Choose a reason for hiding this comment

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

The login query string parameter is no longer needed.

@@ -37,20 +37,6 @@
</head>
Copy link
Member

Choose a reason for hiding this comment

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

This file can be renamed.

@jtojnar jtojnar force-pushed the ppr/client-move branch 2 times, most recently from e73da33 to 3a1c79e Compare June 15, 2017 12:56
Copy link
Member

@jtojnar jtojnar left a comment

Choose a reason for hiding this comment

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

I do not really like the dbOnline but splitting it in a clean way won’t be possible without a significant refactoring. I will merge it as is for now.

@jtojnar jtojnar merged commit c446529 into fossar:master Jun 15, 2017
jtojnar added a commit that referenced this pull request Jun 25, 2017
Pull Request #931 moved the authentication client side, which worsened
the issue #919 by displaying error instead of the login form on opening
selfoss when user did not log out and their session expired on the
server.

This patch redirects user to login form whenever client side session is
registered and 403 Forbidden error is received.

This is a temporary fix before offline support is merged.
jtojnar added a commit that referenced this pull request Jun 27, 2017
Pull Request #931 moved the authentication client side, which worsened
the issue #919 by displaying error instead of the login form on opening
selfoss when user did not log out and their session expired on the
server.

This patch redirects user to login form whenever client side session is
registered and 403 Forbidden error is received.

This is a temporary fix before offline support is merged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants