Skip to content

Commit

Permalink
chore: Remove dead code and replace setTimeout with requestAnimationF…
Browse files Browse the repository at this point in the history
…rame when wait is not necessary
  • Loading branch information
ambroisemaupate committed Sep 18, 2023
1 parent 4f5f714 commit 49a68c4
Show file tree
Hide file tree
Showing 30 changed files with 251 additions and 616 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -250,16 +250,16 @@ public function alterQueryBuilderWithAuthorizationChecker(
*
* @param array $criteria
* @param array|null $orderBy
* @param integer|null $limit
* @param integer|null $offset
* @param int|null $limit
* @param int|null $offset
* @return QueryBuilder
*/
protected function getContextualQuery(
array &$criteria,
array $orderBy = null,
$limit = null,
$offset = null
) {
): QueryBuilder {
$qb = $this->createQueryBuilder(static::NODESSOURCES_ALIAS);
$this->alterQueryBuilderWithAuthorizationChecker($qb, static::NODESSOURCES_ALIAS);
$qb->addSelect(static::NODE_ALIAS);
Expand Down Expand Up @@ -417,7 +417,7 @@ public function findBy(
public function findOneBy(
array $criteria,
array $orderBy = null
) {
): ?NodesSources {
$qb = $this->getContextualQuery(
$criteria,
$orderBy,
Expand Down
26 changes: 3 additions & 23 deletions lib/RoadizCoreBundle/src/Routing/NodeRouteHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ public function getMethod(): string
* Return FALSE or TRUE if node is viewable.
*
* @return bool
* @throws \ReflectionException
*/
public function isViewable(): bool
{
Expand All @@ -120,33 +119,14 @@ public function isViewable(): bool
);
return false;
}
/*
* For archived and deleted nodes
*/
if ($this->node->getStatus() > Node::PUBLISHED) {
/*
* Not allowed to see deleted and archived nodes
* even for Admins
*/
return false;
}

/*
* For unpublished nodes
*/
if ($this->node->getStatus() < Node::PUBLISHED) {
if (true === $this->previewResolver->isPreview()) {
return true;
}
/*
* Not allowed to see unpublished nodes
*/
return false;
if ($this->previewResolver->isPreview()) {
return $this->node->isDraft() || $this->node->isPending() || $this->node->isPublished();
}

/*
* Everyone can view published nodes.
*/
return true;
return $this->node->isPublished();
}
}
21 changes: 5 additions & 16 deletions lib/Rozier/src/Resources/app/Lazyload.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import TagsBulk from './components/bulk-edits/TagsBulk'
import DocumentUploader from './components/documents/DocumentUploader'
import NodeTypeFieldsPosition from './components/node-type-fields/NodeTypeFieldsPosition'
import AttributeValuePosition from './components/attribute-values/AttributeValuePosition'
import NodeTypeFieldEdit from './components/node-type-fields/NodeTypeFieldEdit'
import CustomFormFieldsPosition from './components/custom-form-fields/CustomFormFieldsPosition'
import NodeTreeContextActions from './components/trees/NodeTreeContextActions'
import NodeEditSource from './components/node/NodeEditSource'
Expand All @@ -28,9 +27,6 @@ import MultiLeafletGeotagField from './widgets/MultiLeafletGeotagField'
import TagEdit from './components/tag/TagEdit'
import MainTreeTabs from './components/tabs/MainTreeTabs'

/**
* Lazyload
*/
export default class Lazyload {
constructor() {
this.$linksSelector = null
Expand All @@ -53,7 +49,6 @@ export default class Lazyload {
this.attributeValuesPosition = null
this.customFormFieldsPosition = null
this.settingsSaveButtons = null
this.nodeTypeFieldEdit = null
this.nodeEditSource = null
this.tagEdit = null
this.markdownEditors = []
Expand Down Expand Up @@ -115,14 +110,10 @@ export default class Lazyload {
) {
event.preventDefault()

if (this.clickTimeout) {
clearTimeout(this.clickTimeout)
}

this.clickTimeout = window.setTimeout(() => {
window.requestAnimationFrame(() => {
window.history.pushState({}, null, $link.attr('href'))
this.onPopState(null)
}, 0)
})

return false
}
Expand Down Expand Up @@ -159,10 +150,10 @@ export default class Lazyload {
* Delay loading if user is click like devil
*/
if (this.currentTimeout) {
clearTimeout(this.currentTimeout)
window.cancelAnimationFrame(this.currentTimeout)
}

this.currentTimeout = window.setTimeout(() => {
this.currentTimeout = window.requestAnimationFrame(() => {
/*
* Trigger event on window to notify open
* widgets to close.
Expand Down Expand Up @@ -211,7 +202,7 @@ export default class Lazyload {

this.canvasLoader.hide()
})
}, 100)
})
}

refreshCodemirrorEditor() {
Expand Down Expand Up @@ -303,7 +294,6 @@ export default class Lazyload {
this.attributeValuesPosition,
this.customFormFieldsPosition,
this.settingsSaveButtons,
this.nodeTypeFieldEdit,
this.nodeEditSource,
this.tagEdit,
this.nodeTree,
Expand Down Expand Up @@ -338,7 +328,6 @@ export default class Lazyload {
this.customFormFieldsPosition = new CustomFormFieldsPosition()
this.nodeTreeContextActions = new NodeTreeContextActions()
this.settingsSaveButtons = new SettingsSaveButtons()
this.nodeTypeFieldEdit = new NodeTypeFieldEdit()
this.nodeEditSource = new NodeEditSource()
this.tagEdit = new TagEdit()
this.nodeTree = new NodeTree()
Expand Down
Loading

0 comments on commit 49a68c4

Please sign in to comment.