@uiowa/university-person

An Angular library for common University Person Search.

Usage no npm install needed!

<script type="module">
  import uiowaUniversityPerson from 'https://cdn.skypack.dev/@uiowa/university-person';
</script>

README

University Person Search

An Angular library for common University Person Search.

Library Details

Default Setup

  • In your app.module:
    • Import UniversityPersonModule
    • Provide a substitute class for the UniversityPersonService

Models

  • CanEdit: boolean value that determines if the person is editable. Default is true.
  • IsInvalid: boolean value that determines if the person is invalid, this is to display the person and search field red. Default is false.
  • PersonDisplayTemplate: template that is used to customize the display of the chosen person. If not provided, the default person display will be used.
  • PersonSearchResultsTemplate: template that is used to customized the diplay of the search results in the popup modal. If not provided, the default person search display will be used.
  • OnNoPeopleFound: method that is called when there are no people found for the provided search criteria.

Features

  • Supports registering form control for Reactive Forms.

  • Supports customization for the display of the chosen person and the display of the search results in the popup modal. The personDisplayTemplate gives you access to all of the person properties through the person object variable. The personSearchResultsTemplate gives you access to the people found by the search through the people array variable. You can get access all of the properties and methods from the University Person component by adding a local variable (#universityPerson) to represent the component (https://angular.io/guide/component-interaction).

    <uiowa-university-person 
      formControlName="person" 
      [canEdit]="true" 
      [personDisplayTemplate]="personDisplay" 
      [personSearchResultsTemplate]="personSearchResults"
      #universityPerson>
    </uiowa-university-person>

    <ng-template #personDisplay let-person>
      <p class="mb-0">
        <span class="font-weight-bold">{{person.displayName}}</span>
        <button type="button" class="btn btn-sm btn-outline-secondary align-text-bottom ml-1" (click)="universityPerson.onChangePerson()" *ngIf="universityPerson.canEdit">
          <i class="fa fa-user-edit"></i>
        </button>
        <button type="button" class="btn btn-sm btn-outline-danger align-text-bottom ml-1" (click)="universityPerson.onChangePerson()" *ngIf="universityPerson.canEdit">
          <i class="fa fa-user-minus"></i>
        </button>
      </p>
      <small class="form-text text-muted mt-0">{{person.hawkId}} | {{person.univId}} | {{person.emplId}}</small>
      <small class="form-text text-muted mt-0">{{person.org}}-{{person.department}} | {{person.departmentDescr}}</small>
      <small class="form-text text-muted mt-0">{{person.universityClassification}}</small>
    </ng-template>

    <ng-template #personSearchResults let-people>
      <thead>
        <tr>
          <th></th>
          <th>Name</th>
          <th>University Classification</th>
          <th>Department</th>
          <th>Department Description</th>
        </tr>
      </thead>
      <tbody>
        <tr *ngFor="let person of people">
          <td>
            <button type="button" class="btn btn-primary btn-sm" (click)="universityPerson.onSelectPerson(person)">
              <i class="fa fa-check-square"></i> Select
            </button>
          </td>
          <td>{{person.displayName}}</td>
          <td>{{person.universityClassification}}</td>
          <td>{{person.org}}-{{person.department}}</td>
          <td>{{person.departmentDescr}}</td>
        </tr>
      </tbody>
    </ng-template>
  • Allows the service to search for University people (UniversityPersonService) to be substituted at any level of your application. This means you can provide a substitute class at the app.module level as a default class for the whole application but can also substitute a different class at a lower level (https://angular.io/guide/dependency-injection-providers). For example, you can substitute the UniversityPersonService for a class that calls an endpoint which searches through all people at the app.module level but also substitute a different class that calls an endpoint which only searches through people with a certain property at a specific component level.
  import { UniversityPersonModule, UniversityPersonService } from '@uiowa/university-person';
  import { WhoKeyUniversityPersonService } from './shared/services';

  @NgModule({
    declarations: [AppComponent, HomeComponent],
    imports: [
      BrowserModule,
      BrowserAnimationsModule,
      NgbModule,
      ToastrModule.forRoot(),
      SessionExpirationAlert.forRoot(),
      CoreModule,
      AppRoutingModule,
      SpinnerModule,
      UniversityPersonModule
    ],
    providers: [
      {
        provide: UniversityPersonService,
        useClass: WhoKeyUniversityPersonService
      }
    ],
    bootstrap: [AppComponent]
  })
  export class AppModule {}