Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions com.woltlab.wcf/templates/shared_gridView.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@
'{unsafe:$view->getBaseUrl()|encodeJS}',
'{unsafe:$view->getSortField()|encodeJS}',
'{unsafe:$view->getSortOrder()|encodeJS}',
'{unsafe:$view->getDefaultSortField()|encodeJS}',
'{unsafe:$view->getDefaultSortOrder()|encodeJS}',
'{unsafe:$view->getBulkInteractionProviderClassName()|encodeJS}',
new Map([
{foreach from=$view->getParameters() key='name' item='value'}
Expand Down
25 changes: 22 additions & 3 deletions ts/WoltLabSuite/Core/Component/GridView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export class GridView {
baseUrl: string = "",
sortField = "",
sortOrder = "ASC",
defaultSortField = "",
defaultSortOrder = "ASC",
bulkInteractionProviderClassName: string,
gridViewParameters?: Map<string, string>,
) {
Expand All @@ -42,7 +44,7 @@ export class GridView {
this.#gridViewParameters = gridViewParameters;

this.#initInteractions();
this.#state = this.#setupState(gridId, pageNo, baseUrl, sortField, sortOrder);
this.#state = this.#setupState(gridId, pageNo, baseUrl, sortField, sortOrder, defaultSortField, defaultSortOrder);
this.#initEventListeners();
}

Expand Down Expand Up @@ -117,8 +119,25 @@ export class GridView {
});
}

#setupState(gridId: string, pageNo: number, baseUrl: string, sortField: string, sortOrder: string): State {
const state = new State(gridId, this.#table, pageNo, baseUrl, sortField, sortOrder);
#setupState(
gridId: string,
pageNo: number,
baseUrl: string,
sortField: string,
sortOrder: string,
defaultSortField: string,
defaultSortOrder: string,
): State {
const state = new State(
gridId,
this.#table,
pageNo,
baseUrl,
sortField,
sortOrder,
defaultSortField,
defaultSortOrder,
);
state.addEventListener("grid-view:change", (event) => {
void this.#loadRows(event.detail.source);
});
Expand Down
20 changes: 17 additions & 3 deletions ts/WoltLabSuite/Core/Component/GridView/Sorting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,19 @@ export class Sorting extends EventTarget {
#sortOrder: string;
#table: HTMLTableElement;

constructor(table: HTMLTableElement, sortField: string, sortOrder: string) {
constructor(
table: HTMLTableElement,
sortField: string,
sortOrder: string,
defaultSortField: string,
defaultSortOrder: string,
) {
super();

this.#sortField = sortField;
this.#defaultSortField = sortField;
this.#defaultSortField = defaultSortField;
this.#sortOrder = sortOrder;
this.#defaultSortOrder = sortOrder;
this.#defaultSortOrder = defaultSortOrder;
this.#table = table;

this.#table
Expand Down Expand Up @@ -49,6 +55,14 @@ export class Sorting extends EventTarget {
return [];
}

if (this.#sortField === this.#defaultSortField) {
if (this.#sortOrder !== this.#defaultSortOrder) {
return [["sortOrder", this.#sortOrder]];
} else {
return [];
}
}

return [
["sortField", this.#sortField],
["sortOrder", this.#sortOrder],
Expand Down
4 changes: 3 additions & 1 deletion ts/WoltLabSuite/Core/Component/GridView/State.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export class State extends EventTarget {
baseUrl: string,
sortField: string,
sortOrder: string,
defaultSortField: string,
defaultSortOrder: string,
) {
super();

Expand All @@ -52,7 +54,7 @@ export class State extends EventTarget {
this.#switchPage(1, StateChangeCause.Change);
});

this.#sorting = new Sorting(table, sortField, sortOrder);
this.#sorting = new Sorting(table, sortField, sortOrder, defaultSortField, defaultSortOrder);
this.#sorting.addEventListener("grid-view:change", () => {
this.#switchPage(1, StateChangeCause.Change);
});
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ abstract class AbstractGridView
private GridViewRowLink $rowLink;
private int $rowsPerPage = 20;
private string $baseUrl = '';
private string $defaultSortField = '';
private string $defaultSortOrder = '';
private string $sortField = '';
private string $sortOrder = 'ASC';
private int $pageNo = 1;
Expand Down Expand Up @@ -456,6 +458,44 @@ public function getBaseUrl(): string
return $this->baseUrl;
}

/**
* Sets the default sort field of the grid view.
*/
public function setDefaultSortField(string $sortField): void
{
$this->defaultSortField = $sortField;
$this->setSortField($sortField);
}

/**
* Sets the default sort order of the grid view.
*/
public function setDefaultSortOrder(string $sortOrder): void
{
if ($sortOrder !== 'ASC' && $sortOrder !== 'DESC') {
throw new \InvalidArgumentException("Invalid value '{$sortOrder}' as default sort order given.");
}

$this->defaultSortOrder = $sortOrder;
$this->setSortOrder($sortOrder);
}

/**
* Returns the default sort field of the grid view.
*/
public function getDefaultSortField(): string
{
return $this->defaultSortField;
}

/**
* Returns the sort order of the grid view.
*/
public function getDefaultSortOrder(): string
{
return $this->defaultSortOrder;
}

/**
* Sets the sort field of the grid view.
*/
Expand Down Expand Up @@ -648,6 +688,10 @@ protected function fireInitializedEvent(): void
*/
protected function validate(): void
{
if ($this->getDefaultSortField() === '') {
throw new \InvalidArgumentException("Undefined default sort field.");
}

if ($this->getSortField()) {
if (!\in_array($this->getSortField(), \array_map(fn($column) => $column->getID(), $this->getSortableColumns()))) {
if (\ENABLE_DEBUG_MODE) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ public function __construct(private readonly int $sessionLogID)
),
]);

$this->setSortField('time');
$this->setSortOrder('DESC');
$this->setDefaultSortField('time');
$this->setDefaultSortOrder('DESC');
}

#[\Override]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ public function __construct()
]);

$this->addRowLink(new GridViewRowLink(ACPSessionLogPage::class));
$this->setSortField('lastActivityTime');
$this->setSortOrder('DESC');
$this->setDefaultSortField('lastActivityTime');
$this->setDefaultSortOrder('DESC');
}

#[\Override]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function __construct()
)
);

$this->setSortField("showOrder");
$this->setDefaultSortField("showOrder");
$this->addRowLink(new GridViewRowLink(AdEditForm::class));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ public function render(mixed $value, DatabaseObject $row): string
$this->setInteractionProvider($provider);
$this->setBulkInteractionProvider(new ArticleBulkInteractions());

$this->setSortField('time');
$this->setSortOrder('DESC');
$this->setDefaultSortField('time');
$this->setDefaultSortOrder('DESC');
$this->addRowLink(new GridViewRowLink(ArticleEditForm::class));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,8 @@ public function render(mixed $value, DatabaseObject $row): string
$this->setInteractionProvider($interaction);
$this->setBulkInteractionProvider(new AttachmentBulkInteractions());
$this->addRowLink(new GridViewRowLink(isLinkableObject: true));

$this->setSortOrder('DESC');
$this->setSortField('uploadTime');
$this->setDefaultSortField('uploadTime');
$this->setDefaultSortOrder('DESC');
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function render(mixed $value, DatabaseObject $row): string
]);
$this->setInteractionProvider($provider);

$this->setSortField('bbcodeTag');
$this->setDefaultSortField('bbcodeTag');
$this->addRowLink(new GridViewRowLink(BBCodeEditForm::class));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function __construct()
);

$this->addRowLink(new GridViewRowLink(BBCodeMediaProviderEditForm::class));
$this->setSortField('title');
$this->setDefaultSortField('title');
}

#[\Override]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public function applyFilter(DatabaseObjectList $list, string $id, string $value)

$this->addQuickInteraction(new ToggleInteraction('enable', 'core/boxes/%s/enable', 'core/boxes/%s/disable'));

$this->setSortField('name');
$this->setDefaultSortField('name');
$this->addRowLink(new GridViewRowLink(BoxEditForm::class));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function __construct()
new ToggleInteraction('enable', 'core/captchas/questions/%s/enable', 'core/captchas/questions/%s/disable')
);

$this->setSortField('questionID');
$this->setDefaultSortField('questionID');
$this->addRowLink(new GridViewRowLink(CaptchaQuestionEditForm::class));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ public function __construct()

$this->addRowLink(new GridViewRowLink(ContactOptionEditForm::class));

$this->setSortField("showOrder");
$this->setSortOrder("ASC");
$this->setDefaultSortField("showOrder");
$this->setDefaultSortOrder("ASC");
}

#[\Override]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ public function __construct()

$this->addRowLink(new GridViewRowLink(ContactRecipientEditForm::class));

$this->setSortField("showOrder");
$this->setSortOrder("ASC");
$this->setDefaultSortField("showOrder");
$this->setDefaultSortOrder("ASC");
}

#[\Override]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public function render(mixed $value, DatabaseObject $row): string
$this->setBulkInteractionProvider(new CronjobBulkInteractions());

$this->addRowLink(new GridViewRowLink(CronjobEditForm::class));
$this->setSortField('description');
$this->setDefaultSortField('description');
}

#[\Override]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ public function render(mixed $value, DatabaseObject $row): string
]);

$this->addQuickInteraction($this->getShowDetailsInteraction());
$this->setSortField('execTime');
$this->setSortOrder('DESC');
$this->setDefaultSortField('execTime');
$this->setDefaultSortOrder('DESC');
}

#[\Override]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ public function render(mixed $value, DatabaseObject $row): string
]);

$this->addQuickInteraction($this->getShowDetailsInteraction());
$this->setSortField('time');
$this->setSortOrder('DESC');
$this->setDefaultSortField('time');
$this->setDefaultSortOrder('DESC');
}

#[\Override]
Expand Down
Loading