Skip to content

Commit

Permalink
MOBILE-4348 module: Re-estructure activity card
Browse files Browse the repository at this point in the history
  • Loading branch information
crazyserver committed Sep 28, 2023
1 parent 6cb6d28 commit 468bd7b
Show file tree
Hide file tree
Showing 16 changed files with 297 additions and 215 deletions.
5 changes: 0 additions & 5 deletions src/addons/mod/forum/services/handlers/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { CoreCourseModuleHandler, CoreCourseModuleHandlerData } from '@features/
import { CoreConstants, ModPurpose } from '@/core/constants';
import { CoreModuleHandlerBase } from '@features/course/classes/module-base-handler';
import { CoreCourseModuleData } from '@features/course/services/course-helper';
import { CoreIonicColorNames } from '@singletons/colors';

/**
* Handler to support forum modules.
Expand Down Expand Up @@ -57,7 +56,6 @@ export class AddonModForumModuleHandlerService extends CoreModuleHandlerBase imp
const data = await super.getData(module, courseId);

if ('afterlink' in module && !!module.afterlink) {
data.extraBadgeColor = undefined;
const match = />(\d+)[^<]+/.exec(module.afterlink);
data.extraBadge = match ? Translate.instant('addon.mod_forum.unreadpostsnumber', { $a : match[1] }) : '';
} else {
Expand Down Expand Up @@ -113,7 +111,6 @@ export class AddonModForumModuleHandlerService extends CoreModuleHandlerBase imp
}

data.extraBadge = Translate.instant('core.loading');
data.extraBadgeColor = CoreIonicColorNames.DARK;

try {
// Handle unread posts.
Expand All @@ -122,7 +119,6 @@ export class AddonModForumModuleHandlerService extends CoreModuleHandlerBase imp
siteId,
});

data.extraBadgeColor = undefined;
data.extraBadge = forum.unreadpostscount
? Translate.instant(
'addon.mod_forum.unreadpostsnumber',
Expand All @@ -131,7 +127,6 @@ export class AddonModForumModuleHandlerService extends CoreModuleHandlerBase imp
: '';
} catch {
// Ignore errors.
data.extraBadgeColor = undefined;
data.extraBadge = '';
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/addons/mod/lti/services/handlers/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export class AddonModLtiModuleHandlerService extends CoreModuleHandlerBase imple
): Promise<CoreCourseModuleHandlerData> {
const data = await super.getData(module, courseId, sectionId, forCoursePage);
data.showDownloadButton = false;
data.buttons = [{
data.button = {
icon: 'fas-up-right-from-square',
label: 'addon.mod_lti.launchactivity',
action: (event: Event, module: CoreCourseModuleData, courseId: number): void => {
Expand All @@ -68,7 +68,7 @@ export class AddonModLtiModuleHandlerService extends CoreModuleHandlerBase imple

CoreCourse.storeModuleViewed(courseId, module.id);
},
}];
};

return data;
}
Expand Down
101 changes: 52 additions & 49 deletions src/addons/mod/resource/services/handlers/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ export class AddonModResourceModuleHandlerService extends CoreModuleHandlerBase

const handlerData = await super.getData(module, courseId, sectionId, forCoursePage);
handlerData.updateStatus = (status) => {
if (!handlerData.buttons) {
if (!handlerData.button) {
return;
}

handlerData.buttons[0].hidden = status !== CoreConstants.DOWNLOADED ||
handlerData.button.hidden = status !== CoreConstants.DOWNLOADED ||
AddonModResourceHelper.isDisplayedInIframe(module);
};
handlerData.buttons = [{
handlerData.button = {
hidden: true,
icon: openWithPicker ? 'fas-share-from-square' : 'fas-file',
label: module.name + ': ' + Translate.instant(openWithPicker ? 'core.openwith' : 'addon.mod_resource.openthefile'),
Expand All @@ -92,7 +92,7 @@ export class AddonModResourceModuleHandlerService extends CoreModuleHandlerBase
CoreCourse.storeModuleViewed(courseId, module.id);
}
},
}];
};

this.getResourceData(module, courseId, handlerData).then((extra) => {
handlerData.extraBadge = extra;
Expand Down Expand Up @@ -144,11 +144,11 @@ export class AddonModResourceModuleHandlerService extends CoreModuleHandlerBase

// Check if the button needs to be shown or not.
promises.push(this.hideOpenButton(module).then((hideOpenButton) => {
if (!handlerData.buttons) {
if (!handlerData.button) {
return;
}

handlerData.buttons[0].hidden = hideOpenButton;
handlerData.button.hidden = hideOpenButton;

return;
}));
Expand All @@ -166,58 +166,61 @@ export class AddonModResourceModuleHandlerService extends CoreModuleHandlerBase

await Promise.all(promises);

const extra: string[] = [];

if (module.contentsinfo) {
// No need to use the list of files.
extra.push(CoreTextUtils.cleanTags(module.afterlink));
} else if (module.contents && module.contents[0]) {
const files = module.contents;
const file = files[0];
return CoreTextUtils.cleanTags(module.afterlink);
}

if (!module.contents || !module.contents[0]) {
return '';
}

if (options.showsize) {
const size = options.filedetails
? options.filedetails.size
: files.reduce((result, file) => result + (file.filesize || 0), 0);
const extra: string[] = [];
const files = module.contents;
const mainFile = files[0];

extra.push(CoreTextUtils.bytesToSize(size, 1));
}
if (options.showsize) {
const size = options.filedetails
? options.filedetails.size
: files.reduce((result, file) => result + (file.filesize || 0), 0);

if (options.showtype) {
// We should take it from options.filedetails.size if available but it's already translated.
extra.push(CoreMimetypeUtils.getMimetypeDescription(file));
}
extra.push(CoreTextUtils.bytesToSize(size, 1));
}

if (options.showdate) {
const timecreated = 'timecreated' in file ? file.timecreated : 0;

if (options.filedetails && options.filedetails.modifieddate) {
extra.push(Translate.instant(
'addon.mod_resource.modifieddate',
{ $a: CoreTimeUtils.userDate(options.filedetails.modifieddate * 1000, 'core.strftimedatetimeshort') },
));
} else if (options.filedetails && options.filedetails.uploadeddate) {
extra.push(Translate.instant(
'addon.mod_resource.uploadeddate',
{ $a: CoreTimeUtils.userDate(options.filedetails.uploadeddate * 1000, 'core.strftimedatetimeshort') },
));
} else if ((file.timemodified || 0) > timecreated + CoreConstants.SECONDS_MINUTE * 5) {
/* Modified date may be up to several minutes later than uploaded date just because
teacher did not submit the form promptly. Give teacher up to 5 minutes to do it. */
extra.push(Translate.instant(
'addon.mod_resource.modifieddate',
{ $a: CoreTimeUtils.userDate((file.timemodified || 0) * 1000, 'core.strftimedatetimeshort') },
));
} else {
extra.push(Translate.instant(
'addon.mod_resource.uploadeddate',
{ $a: CoreTimeUtils.userDate(timecreated * 1000, 'core.strftimedatetimeshort') },
));
}
if (options.showtype) {
// We should take it from options.filedetails.size if available but it's already translated.
extra.push(CoreMimetypeUtils.getMimetypeDescription(mainFile));
}

if (options.showdate) {
const timecreated = 'timecreated' in mainFile ? mainFile.timecreated : 0;

if (options.filedetails && options.filedetails.modifieddate) {
extra.push(Translate.instant(
'addon.mod_resource.modifieddate',
{ $a: CoreTimeUtils.userDate(options.filedetails.modifieddate * 1000, 'core.strftimedatetimeshort') },
));
} else if (options.filedetails && options.filedetails.uploadeddate) {
extra.push(Translate.instant(
'addon.mod_resource.uploadeddate',
{ $a: CoreTimeUtils.userDate(options.filedetails.uploadeddate * 1000, 'core.strftimedatetimeshort') },
));
} else if ((mainFile.timemodified || 0) > timecreated + CoreConstants.SECONDS_MINUTE * 5) {
/* Modified date may be up to several minutes later than uploaded date just because
teacher did not submit the form promptly. Give teacher up to 5 minutes to do it. */
extra.push(Translate.instant(
'addon.mod_resource.modifieddate',
{ $a: CoreTimeUtils.userDate((mainFile.timemodified || 0) * 1000, 'core.strftimedatetimeshort') },
));
} else {
extra.push(Translate.instant(
'addon.mod_resource.uploadeddate',
{ $a: CoreTimeUtils.userDate(timecreated * 1000, 'core.strftimedatetimeshort') },
));
}
}

return extra.join(' ');
return extra.join(' · ');
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/addons/mod/url/services/handlers/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,20 +93,20 @@ export class AddonModUrlModuleHandlerService extends CoreModuleHandlerBase imple
modal.dismiss();
}
},
buttons: [{
button: {
hidden: true, // Hide it until we calculate if it should be displayed or not.
icon: 'fas-link',
label: 'core.openmodinbrowser',
action: (event: Event, module: CoreCourseModuleData, courseId: number): void => {
openUrl(module, courseId);
},
}],
},
};

const hideButton = await CoreUtils.ignoreErrors(this.hideLinkButton(module));

if (handlerData.buttons && hideButton !== undefined) {
handlerData.buttons[0].hidden = hideButton;
if (handlerData.button && hideButton !== undefined) {
handlerData.button.hidden = hideButton;
}

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,5 @@
}

.course-section {
--padding-start: 12px;
--inner-padding-end: 12px;
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ <h2 *ngIf="!isTrackedUser">{{ 'core.course.studentsmust' | translate }}</h2>

<!-- Show only description (without status) to non-tracked users. -->
<div *ngIf="!isTrackedUser" role="listitem" [attr.aria-label]="rule.accessibleDescription">
<ion-icon name="fas-circle" aria-hidden="true"></ion-icon>
<ion-icon name="fas-circle" class="completion_dot" aria-hidden="true"></ion-icon>
{{ rule.rulevalue.description }}
</div>
</ng-container>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
:host {
min-width: var(--a11y-min-target-size);
min-height: var(--a11y-min-target-size);
display: contents;
--size: 30px;

img {
padding: 5px;
padding: 2px;
width: var(--size);
vertical-align: middle;
max-width: none;
margin: 7px;
margin: 4px;
}

ion-button {
--padding-top: 0px;
--padding-start: 0px;
--padding-end: 0px;
--padding-bottom: 0px;
margin: 0;
--a11y-target-min-size: 32px;
width: var(--a11y-target-min-size);
height: var(--a11y-target-min-size);
min-width: var(--a11y-target-min-size);
min-height: var(--a11y-target-min-size);;
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
:host {
display: contents;
display: block;
margin: var(--margin, 4px);

ion-button {
margin: var(--margin, 4px);
margin: 0px;
}

ion-button.button-solid.ion-color-success::part(native){
Expand Down
Loading

0 comments on commit 468bd7b

Please sign in to comment.