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
19 changes: 15 additions & 4 deletions api/src/main/kotlin/edu/wgu/osmt/api/model/ApiKeyword.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@ package edu.wgu.osmt.api.model

import com.fasterxml.jackson.annotation.JsonInclude
import com.fasterxml.jackson.annotation.JsonProperty
import edu.wgu.osmt.config.AppConfig
import edu.wgu.osmt.keyword.Keyword
import edu.wgu.osmt.keyword.KeywordDao
import edu.wgu.osmt.keyword.KeywordTypeEnum
import org.springframework.beans.factory.annotation.Autowired

@JsonInclude(JsonInclude.Include.ALWAYS)
class ApiKeyword(
private val keyword: Keyword,
private val totalSkills: Long?
private val totalSkills: Long?,
private val appConfig: AppConfig
) {
@get:JsonProperty
val id: Long?
Expand All @@ -35,22 +38,30 @@ class ApiKeyword(
val skillCount: Long?
get() = totalSkills

@get:JsonProperty
val publicUrl: String
get() = "${appConfig.baseUrl}/api/metadata/keywords/${id}"

companion object {
fun fromDao(
keywordDao: KeywordDao,
appConfig: AppConfig
): ApiKeyword {
return ApiKeyword(
keyword = keywordDao.toModel(),
totalSkills = keywordDao.skills.count()
totalSkills = keywordDao.skills.count(),
appConfig = appConfig
)
}

fun fromModel(
keyword: Keyword
keyword: Keyword,
appConfig: AppConfig
): ApiKeyword {
return ApiKeyword(
totalSkills = keyword.id?.let { KeywordDao.findById(it)?.skills?.count() ?: 0 },
keyword = keyword
keyword = keyword,
appConfig = appConfig
)
}
}
Expand Down
18 changes: 14 additions & 4 deletions api/src/main/kotlin/edu/wgu/osmt/keyword/KeywordController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.ResponseBody
import org.springframework.web.server.ResponseStatusException
Expand Down Expand Up @@ -74,7 +75,16 @@ class KeywordController @Autowired constructor(

return ResponseEntity.status(200)
.headers(responseHeaders)
.body(searchResults.map { ApiKeyword.fromModel(it.content) }.toList())
.body(searchResults.map { ApiKeyword.fromModel(it.content, appConfig) }.toList())
}

@RequestMapping(path = [
"${RoutePaths.API}${RoutePaths.UNVERSIONED}${RoutePaths.KEYWORD_DETAIL}"
],
produces = [MediaType.TEXT_HTML_VALUE])
fun byUUIDHtmlView(@PathVariable id: String): String {
System.out.println("here by uuid html view keyword")
return "forward:${RoutePaths.UNVERSIONED}/metadata/keywords/$id"
}

@GetMapping(
Expand Down Expand Up @@ -104,7 +114,7 @@ class KeywordController @Autowired constructor(

return ResponseEntity
.status(HttpStatus.OK)
.body(keywordRepository.createFromApi(apiKeywordUpdate)?.let { ApiKeyword(it.toModel(), it.skills.count()) })
.body(keywordRepository.createFromApi(apiKeywordUpdate)?.let { ApiKeyword(it.toModel(), it.skills.count(), appConfig) })
}

@PostMapping(
Expand All @@ -126,7 +136,7 @@ class KeywordController @Autowired constructor(
oAuthHelper.readableUserName(user)
)
?.let {
ApiKeyword(it.toModel(), it.skills.count())
ApiKeyword(it.toModel(), it.skills.count(), appConfig)
}
)
}
Expand All @@ -149,7 +159,7 @@ class KeywordController @Autowired constructor(
private fun byId(
id: Long,
): ApiKeyword? {
val found = keywordRepository.findById(id)?.let { ApiKeyword(it.toModel(), it.skills.count()) }
val found = keywordRepository.findById(id)?.let { ApiKeyword(it.toModel(), it.skills.count(), appConfig) }
return found
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class SecurityConfig : WebSecurityConfigurerAdapter() {
.mvcMatchers(GET, "${RoutePaths.API}${RoutePaths.API_V3}${RoutePaths.SKILL_DETAIL}",
"${RoutePaths.API}${RoutePaths.API_V2}${RoutePaths.SKILL_DETAIL}",
"${RoutePaths.API}${RoutePaths.UNVERSIONED}${RoutePaths.SKILL_DETAIL}").permitAll()
.mvcMatchers(GET,"${RoutePaths.API}${RoutePaths.UNVERSIONED}${RoutePaths.KEYWORD_DETAIL}").permitAll()
.mvcMatchers(GET, "${RoutePaths.API}${RoutePaths.API_V3}${RoutePaths.COLLECTION_DETAIL}",
"${RoutePaths.API}${RoutePaths.API_V2}${RoutePaths.COLLECTION_DETAIL}",
"${RoutePaths.API}${RoutePaths.UNVERSIONED}${RoutePaths.COLLECTION_DETAIL}").permitAll()
Expand Down
6 changes: 4 additions & 2 deletions api/src/test/kotlin/edu/wgu/osmt/api/model/ApiKeywordTest.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package edu.wgu.osmt.api.model

import edu.wgu.osmt.config.AppConfig
import edu.wgu.osmt.keyword.Keyword
import edu.wgu.osmt.mockdata.MockData
import org.assertj.core.api.Assertions
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestInstance
import org.springframework.beans.factory.annotation.Autowired

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
internal class ApiKeywordTest {
Expand All @@ -23,11 +25,11 @@ internal class ApiKeywordTest {
val kw: Keyword = mockData.getKeywords().first()

// Act
val api: ApiKeyword = ApiKeyword(kw, 7)
val api: ApiKeyword = ApiKeyword(kw, 7, mockData.appConfig)

// Assert
Assertions.assertThat(api.id).isEqualTo(kw.id)
Assertions.assertThat(api.type).isEqualTo(kw.type)
Assertions.assertThat(api.name).isEqualTo(kw.value)
}
}
}
26 changes: 16 additions & 10 deletions ui/src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,14 @@ const routes: Routes = [

/* KEYWORDS */

{path: "metadata",
{
path: "metadata",
component: MetadataListComponent,
canActivate: [AuthGuard],
},
// create metadata
{path: "named-references/create",
{
path: "named-references/create",
component: NamedReferenceFormComponent,
canActivate: [AuthGuard],
data: {
Expand All @@ -109,7 +111,8 @@ const routes: Routes = [
},
},*/
// edit metadata
{path: "named-references/:id/edit",
{
path: "named-references/:id/edit",
component: NamedReferenceFormComponent,
canActivate: [AuthGuard],
data: {
Expand All @@ -124,20 +127,19 @@ const routes: Routes = [
},
},*/
// public metadata detail
{path: "named-references/:id",
component: MetadataPublicComponent,
canActivate: [AuthGuard]
},
{path: "job-codes/:id",
{
path: "job-codes/:id",
component: MetadataPublicComponent,
canActivate: [AuthGuard]
},
// admin metadata detail
{path: "named-references/:id/manage",
{
path: "named-references/:id/manage",
component: MetadataManageComponent,
canActivate: [AuthGuard]
},
{path: "job-codes/:id/manage",
{
path: "job-codes/:id/manage",
component: MetadataManageComponent,
canActivate: [AuthGuard]
},
Expand Down Expand Up @@ -246,6 +248,10 @@ const routes: Routes = [
{path: "collections/:uuid", component: CollectionPublicComponent},
{path: "api/skills/:uuid", component: RichSkillPublicComponent},
{path: "api/collections/:uuid", component: CollectionPublicComponent},
{
path: "api/metadata/keywords/:id",
component: MetadataPublicComponent
},

/* AUTHENTICATION REDIRECTS */
{path: "login", component: LoginComponent}, // redirect to oauth login
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,15 @@ export abstract class AbstractMetadataDetailComponent extends QuickLinksHelper i

protected setMetadata(metadata: ApiNamedReference | ApiJobCode) {
this.metadata = metadata;
console.log(this.metadata)

// this.titleService.setTitle(`${category.name} | Category | ${this.whitelabel.toolName}`)
this.loadSkills();
}

protected loadSkills(): void {
if (this.metadata) {
this.skillTableControl.loadSkills(this.getId())
this.skillTableControl.loadSkills(this.idParam ?? -1)
} else {
this.clearSkills();
}
Expand All @@ -153,6 +154,10 @@ export abstract class AbstractMetadataDetailComponent extends QuickLinksHelper i
return this.metadata?.id ?? -1;
}

getPublicUrl(): string {
return (this.metadata as any)?.publicUrl ?? "";
}

getCardFormat(): IDetailCardSectionData[] {
return [];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<div class="l-container l-container-mobile t-margin-medium t-margin-bottom">
<h2 *ngIf="title" class="t-type-heading1 t-margin-small t-margin-bottom" #titleHeading>{{title}}</h2>
<p class="t-type-bodyLarge t-type-text3">
{{metadataCountLabel}}
{{metadataCountLabel}}.

<span *ngIf="matchingQuery">
found based on
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { NamedReferenceService } from "../../named-reference/service/named-refer
})
export class MetadataListComponent extends AbstractListComponent<IJobCode | NamedReferenceInterface> implements OnInit {

selectedMetadataType = MetadataType.Category
selectedMetadataType = Object.values(MetadataType)[0];

typeControl: FormControl = new FormControl(this.selectedMetadataType)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<app-manage-metadata-action-bar-vertical
[id]="getId()"
[metadataName]="getMetadataName()"
[metadataPublicUrl]="getId()"
[metadataPublicUrl]="getPublicUrl()"
(reloadMetadata)="loadMetadata()"
></app-manage-metadata-action-bar-vertical>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<app-public-metadata-action-bar-vertical
[id]="getId()"
[metadataName]="getMetadataName()"
[metadataPublicUrl]="getId()"
[metadataPublicUrl]="getPublicUrl()"
(reloadMetadata)="loadMetadata()"
></app-public-metadata-action-bar-vertical>

Expand Down Expand Up @@ -60,7 +60,7 @@ <h3 class="t-visuallyHidden" id="save-quicklinks">Quick Links</h3>
<div class="t-margin-medium t-margin-bottom">
<app-skill-table
*ngIf="showSkillsTable"
[items]="skills"
[items]="skillTableControl.skills"
[showRowActions]="false"
[currentSort]="skillTableControl.sort"
[mobileSortOptions]="getMobileSkillSortOptions()"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
Select a type of Metadata
</label>
<select name="metadata-selection" #type (change)="onValueChange(type.value)" [ngModel]="currentSelection" class="m-text select">
<option [value]="value.value" *ngFor="let value of MetadataType | keyvalue">
{{ value.value | titlecase }}
<option [value]="value" *ngFor="let value of types">
{{ value | titlecase }}
</option>
</select>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,18 @@ export class MetadataSelectorComponent {
@Input()
currentSelection?: string

protected readonly MetadataType = MetadataType
types: string[] = []
@Input()
isVisible: () => boolean = () => false

constructor() {
this.types = Object.values(MetadataType).sort((a, b) => {
if(a < b) { return -1; }
if(a > b) { return 1; }
return 0;
})
}

onValueChange(value: string): void {
this.control?.patchValue(value)
this.currentSelection = value
Expand Down
2 changes: 2 additions & 0 deletions ui/src/app/metadata/named-reference/NamedReference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export interface NamedReferenceInterface {
url: string
framework: string
skillCount: number
publicUrl: string
}

export class ApiNamedReference implements NamedReferenceInterface {
Expand All @@ -16,6 +17,7 @@ export class ApiNamedReference implements NamedReferenceInterface {
type?: MetadataType = MetadataType.Category
url = ""
skillCount: number = 0
publicUrl = ""

constructor(o?: NamedReferenceInterface) {
if (o !== undefined) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ <h3 class="m-iconTitle">
</app-formfield-text>
</div>

<div class="t-margin-medium t-margin-bottom">
<div class="t-margin-medium t-margin-bottom" *ngIf="isAlignment()">
<app-formfield-text
[control]="metadataForm.controls.framework"
name="metadataValue"
Expand All @@ -45,7 +45,7 @@ <h3 class="m-iconTitle">
></app-formfield-text>
</div>

<div class="t-margin-medium t-margin-bottom">
<div class="t-margin-medium t-margin-bottom" *ngIf="isAlignment()">
<app-formfield-text
[control]="metadataForm.controls.uri"
name="metadataValue"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { FormBuilder, FormGroup, Validators } from "@angular/forms"
import { ActivatedRoute, Router } from "@angular/router"
import { Location } from "@angular/common"
import { NamedReferenceService } from "../service/named-reference.service"
import { MetadataType } from "../../rsd-metadata.enum"

@Component({
selector: 'app-create',
Expand All @@ -22,6 +23,10 @@ export class NamedReferenceFormComponent extends MetadataFormComponent {
super(route, router, location, formBuilder, namedReferenceService)
}

isAlignment(): boolean {
return this.metadataType == Object.keys(MetadataType)[Object.values(MetadataType).indexOf(MetadataType.Alignment)];
}

getFormDefinitions(): FormGroup {
return this.formBuilder.group({
name: [undefined, [Validators.required]],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<use [attr.xlink:href]="duplicateIcon"></use>
</svg>
</span>
<span class="m-actionBarItem-x-text">Copy URLdd</span>
<span class="m-actionBarItem-x-text">Copy URL</span>
<label>
<textarea class="t-visuallyHidden" #fullPath>{{skillUrl}}</textarea>
</label>
Expand Down
2 changes: 1 addition & 1 deletion ui/test/resource/mock-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export function createMockNamedReference2(
url = "http://url123",
framework = "Framework"
): NamedReferenceInterface {
return {id,name,type,url,framework, skillCount: 0
return {id,name,type,url,framework, skillCount: 0, publicUrl: url
}
}

Expand Down