Skip to content

Commit

Permalink
Merge pull request #65 from UCI-IN4MATX-191-Token-ATM/refactor-token-…
Browse files Browse the repository at this point in the history
…options

Enhancement & Refactoring: token otpion fields validation enhancement & token option refactoring
  • Loading branch information
epsilonError authored Aug 22, 2023
2 parents 66b461b + 50c9070 commit 6a111de
Show file tree
Hide file tree
Showing 79 changed files with 3,053 additions and 1,824 deletions.
102 changes: 102 additions & 0 deletions package-lock.json

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

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@
"axios": "^1.3.5",
"bootstrap": "^5.2.3",
"bootstrap-icons": "^1.10.5",
"camelcase-keys": "^8.0.2",
"compress-json": "^2.1.2",
"date-fns": "^2.30.0",
"decamelize-keys": "^2.0.1",
"flatted": "^3.2.7",
"fp-ts": "^2.16.1",
"html-dom-parser": "^3.1.7",
Expand Down
4 changes: 3 additions & 1 deletion src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import {
} from './token-option-field-component-factories/token-option-field-component-factory-registry';
import { CreateTokenOptionModalComponent } from './components/create-token-option-modal/create-token-option-modal.component';
import { MultipleSectionDateFieldComponent } from './components/form-fields/multiple-section-date-field/multiple-section-date-field.component';
import { ErrorMessageFieldComponent } from './components/form-fields/error-message-field/error-message-field.component';

@NgModule({
declarations: [
Expand Down Expand Up @@ -96,7 +97,8 @@ import { MultipleSectionDateFieldComponent } from './components/form-fields/mult
ListFieldItemWrapperComponent,
ListFieldComponent,
CreateTokenOptionModalComponent,
MultipleSectionDateFieldComponent
MultipleSectionDateFieldComponent,
ErrorMessageFieldComponent
],
imports: [
BrowserModule,
Expand Down
70 changes: 37 additions & 33 deletions src/app/components/configuration/configuration.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import { TokenOptionGroup } from 'app/data/token-option-group';
import { CanvasService } from 'app/services/canvas.service';
import { ModalManagerService } from 'app/services/modal-manager.service';
import { TokenATMConfigurationManagerService } from 'app/services/token-atm-configuration-manager.service';
import { BasicTokenOption } from 'app/token-options/basic-token-option';
import { EarnByModuleTokenOption } from 'app/token-options/earn-by-module-token-option';
import type { BasicTokenOptionData } from 'app/token-options/basic-token-option';
import type { EarnByModuleTokenOptionData } from 'app/token-options/earn-by-module-token-option';
import { BsModalRef, BsModalService } from 'ngx-bootstrap/modal';
import type { CourseConfigurable } from '../dashboard/dashboard-routing';
import { ErrorSerializer } from 'app/utils/error-serailizer';
import { EditConfigurationModalComponent } from '../edit-configuration-modal/edit-configuration-modal.component';
import { TokenOptionResolverRegistry } from 'app/token-option-resolvers/token-option-resolver-registry';

@Component({
selector: 'app-configuration',
Expand All @@ -30,6 +31,7 @@ export class ConfigurationComponent implements CourseConfigurable {
private configurationManagerService: TokenATMConfigurationManagerService,
@Inject(CanvasService) private canvasService: CanvasService,
@Inject(BsModalService) private modalSerivce: BsModalService,
@Inject(TokenOptionResolverRegistry) private tokenOptionResolverRegistry: TokenOptionResolverRegistry,
@Inject(ModalManagerService) private modalManagerSerivce: ModalManagerService
) {}

Expand Down Expand Up @@ -70,27 +72,29 @@ export class ConfigurationComponent implements CourseConfigurable {
[]
);
await this.configurationManagerService.addNewTokenOptionGroup(basicGroup);
basicGroup.addTokenOption(
new BasicTokenOption(
basicGroup,
'basic',
configuration.nextFreeTokenOptionId,
'Earn 0.5 test tokens',
const basicTokenOption1Data: BasicTokenOptionData = {
type: 'basic',
id: configuration.nextFreeTokenOptionId,
name: 'Earn 0.5 test tokens',
description:
'The test tokens you obtained by requesting this token option is just for testing purpose and will not influence your real token counts',
0.5,
false
)
tokenBalanceChange: 0.5,
isMigrating: false
};
const basicTokenOption2Data: BasicTokenOptionData = {
type: 'basic',
id: configuration.nextFreeTokenOptionId,
name: 'Spend 1 test token',
description:
'The test tokens you spent by requesting this token option is just for testing purpose and will not influence your real token counts',
tokenBalanceChange: -1,
isMigrating: false
};
basicGroup.addTokenOption(
this.tokenOptionResolverRegistry.constructTokenOption(basicGroup, basicTokenOption1Data)
);
basicGroup.addTokenOption(
new BasicTokenOption(
basicGroup,
'basic',
configuration.nextFreeTokenOptionId,
'Spend 1 test token',
'The test tokens you spent by requesting this token option is just for testing purpose and will not influence your real token counts',
-1,
false
)
this.tokenOptionResolverRegistry.constructTokenOption(basicGroup, basicTokenOption2Data)
);
await this.configurationManagerService.updateTokenOptionGroup(basicGroup);
const moduleGroup = new TokenOptionGroup(
Expand Down Expand Up @@ -120,20 +124,20 @@ export class ConfigurationComponent implements CourseConfigurable {
});
await moduleNamePromise;
const moduleId = await this.canvasService.getModuleIdByName(this.course.id, this.moduleName as string);
const moduleTokenOptionData: EarnByModuleTokenOptionData = {
type: 'earn-by-module',
id: configuration.nextFreeTokenOptionId,
name: `Course Preparation Token`,
description: `To get this test token, you need to pass the Course Preparation Module with a score no less than 70% of the total score. The test token you got is just for testing purpose and will not influence your real token counts`,
tokenBalanceChange: 1,
isMigrating: false,
moduleName: this.moduleName as string,
moduleId,
startTime: new Date(),
gradeThreshold: 0.7
};
moduleGroup.addTokenOption(
new EarnByModuleTokenOption(
moduleGroup,
'earn-by-module',
configuration.nextFreeTokenOptionId,
`Course Preparation Token`,
`To get this test token, you need to pass the Course Preparation Module with a score no less than 70% of the total score. The test token you got is just for testing purpose and will not influence your real token counts`,
1,
false,
this.moduleName as string,
moduleId,
new Date(),
0.7
)
this.tokenOptionResolverRegistry.constructTokenOption(moduleGroup, moduleTokenOptionData)
);
await this.configurationManagerService.updateTokenOptionGroup(moduleGroup);
this.isProcessing = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ export class CourseSelectionComponent implements OnInit {
}

async onSelectCourse(course: Course): Promise<void> {
// TODO-Now
this.loading = true;
try {
await this.configurationManagerService.getTokenATMConfiguration(course);
Expand Down
5 changes: 0 additions & 5 deletions src/app/components/dev-test/dev-test.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,5 @@
Publish/Unpublish Last Token Option Group
</button>
<button class="btn btn-danger my-3" (click)="onResetStudentRecord()">Reset all student records</button>
<button class="btn btn-danger my-3" (click)="onPopulateICSExpoConfiguration()">
Populate ICS Expo Testing Configuration
</button>
<button class="btn btn-danger my-3" (click)="onMyOperation()">On My Operation</button>
<button class="btn btn-danger my-3" (click)="onMyOperation1()">On My Operation 1</button>
<ng-template #container></ng-template>
</div>
Loading

0 comments on commit 6a111de

Please sign in to comment.