Skip to content

Commit

Permalink
implementation (Languages): #28476 Support the different Menu actions…
Browse files Browse the repository at this point in the history
… in the table. (#28669)

### Proposed Changes
* add the menu options to the locale table and the confirmation
messages.
* Push Publish 
* Set As Default 
* Delete 


### Screenshots


https://github.com/dotCMS/core/assets/31667212/646d62f0-b6d3-4f8d-b9e4-173e955160b8
  • Loading branch information
hmoreras authored May 30, 2024
1 parent 3d1eccf commit 886ffe4
Show file tree
Hide file tree
Showing 19 changed files with 806 additions and 205 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { createHttpFactory, HttpMethod, SpectatorHttp } from '@ngneat/spectator/jest';

import { DotLanguagesService } from '@dotcms/data-access';
import {
DotLanguagesService,
LANGUAGE_API_URL,
LANGUAGE_API_URL_WITH_VARS
} from '@dotcms/data-access';
import { DotLanguage } from '@dotcms/dotcms-models';

describe('DotLanguagesService', () => {
let spectator: SpectatorHttp<DotLanguagesService>;
Expand All @@ -10,18 +15,65 @@ describe('DotLanguagesService', () => {

it('should get Languages', () => {
spectator.service.get().subscribe();
spectator.expectOne(`/api/v2/languages`, HttpMethod.GET);
spectator.expectOne(LANGUAGE_API_URL_WITH_VARS, HttpMethod.GET);
});

it('should get Languages by content indode', () => {
const contentInode = '2';
spectator.service.get(contentInode).subscribe();
spectator.expectOne(`/api/v2/languages?contentInode=${contentInode}`, HttpMethod.GET);
spectator.expectOne(
`${LANGUAGE_API_URL_WITH_VARS}&contentInode=${contentInode}`,
HttpMethod.GET
);
});

it('should get Languages by pageId', () => {
const pageIdentifier = '0000-1111-2222-3333';
spectator.service.getLanguagesUsedPage(pageIdentifier).subscribe();
spectator.expectOne(`/api/v1/page/${pageIdentifier}/languages`, HttpMethod.GET);
});

it('should add a new language', () => {
const language = {
languageCode: 'fr',
countryCode: 'FR',
language: 'French',
country: 'France'
};
spectator.service.add(language).subscribe();
const req = spectator.expectOne(LANGUAGE_API_URL, HttpMethod.POST);
expect(req.request.body).toEqual(language);
});

it('should get a language by id', () => {
const id = 1;
spectator.service.getById(id).subscribe();
spectator.expectOne(`${LANGUAGE_API_URL}/id/${id}`, HttpMethod.GET);
});

it('should update a language', () => {
const language = {
id: '1',
languageCode: 'fr'
} as unknown as DotLanguage;
spectator.service.update(language).subscribe();
spectator.expectOne(`${LANGUAGE_API_URL}/${language.id}`, HttpMethod.PUT);
});

it('should delete a language by id', () => {
const id = 1;
spectator.service.delete(id).subscribe();
spectator.expectOne(`${LANGUAGE_API_URL}/${id}`, HttpMethod.DELETE);
});

it('should make a language the default language', () => {
const id = 1;
spectator.service.makeDefault(id).subscribe();
spectator.expectOne(`${LANGUAGE_API_URL}/${id}/_makedefault`, HttpMethod.PUT);
});

it('should get languages and countries in ISO format', () => {
spectator.service.getISO().subscribe();
spectator.expectOne(`${LANGUAGE_API_URL}/iso`, HttpMethod.GET);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import { inject, Injectable } from '@angular/core';

import { pluck } from 'rxjs/operators';

import { DotLanguage } from '@dotcms/dotcms-models';
import { DotAddLanguage, DotLanguage, DotLanguagesISO } from '@dotcms/dotcms-models';

export const LANGUAGE_API_URL = '/api/v2/languages';

export const LANGUAGE_API_URL_WITH_VARS = '/api/v2/languages?countLangVars=true';

/**
* Provide util methods to get Languages available in the system.
Expand All @@ -23,8 +27,8 @@ export class DotLanguagesService {
*/
get(contentInode?: string): Observable<DotLanguage[]> {
const url = !contentInode
? '/api/v2/languages'
: `/api/v2/languages?contentInode=${contentInode}`;
? LANGUAGE_API_URL_WITH_VARS
: `${LANGUAGE_API_URL_WITH_VARS}&contentInode=${contentInode}`;

return this.httpClient.get(url).pipe(pluck('entity'));
}
Expand All @@ -40,4 +44,62 @@ export class DotLanguagesService {
.get(`/api/v1/page/${pageIdentifier}/languages`)
.pipe(pluck('entity'));
}

/**
* Add a new language to the system.
*
* @param {DotAddLanguage} language - The language to be added.
* @return {Observable<DotLanguage>} An observable of the language added.
*/
add(language: DotAddLanguage): Observable<DotLanguage> {
return this.httpClient.post(LANGUAGE_API_URL, language).pipe(pluck('entity'));
}

/**
* Get Language by id.
*
* @param {number} id
* @return {Observable<DotLanguage>}
*/
getById(id: number): Observable<DotLanguage> {
return this.httpClient.get(`${LANGUAGE_API_URL}/id/${id}`).pipe(pluck('entity'));
}

/**
* Update a language.
*
* @param {DotLanguage} language - The language to be updated.
* @return {Observable<DotLanguage>} An observable of the updated language.
*/
update(language: DotLanguage): Observable<DotLanguage> {
return this.httpClient
.put(`${LANGUAGE_API_URL}/${language.id}`, language)
.pipe(pluck('entity'));
}

/**
* Delete a language.
*
* @param {string} id -
* @return {Observable<void>}
*/
delete(id: number): Observable<void> {
return this.httpClient.delete(`${LANGUAGE_API_URL}/${id}`).pipe(pluck('entity'));
}

/**
* Make a language the default language.
*
* @param {number} id - The identifier of the language to be made the default.
* @return {Observable<void>}
*/
makeDefault(id: number): Observable<void> {
return this.httpClient
.put(`${LANGUAGE_API_URL}/${id}/_makedefault`, {})
.pipe(pluck('entity'));
}

getISO(): Observable<DotLanguagesISO> {
return this.httpClient.get(`${LANGUAGE_API_URL}/iso`).pipe(pluck('entity'));
}
}
22 changes: 18 additions & 4 deletions core-web/libs/dotcms-models/src/lib/dot-language.model.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
export interface DotLanguage {
id: number;
languageCode: string;
export interface DotAddLanguage {
country: string;
countryCode: string;
language: string;
country: string;
languageCode: string;
}

export interface DotLanguage extends DotAddLanguage {
id: number;
defaultLanguage?: boolean;
translated?: boolean;
isoCode?: string;
variables?: { count: number; total: number };
}

export interface DotISOItem {
code: string;
name: string;
}

export interface DotLanguagesISO {
countries: DotISOItem[];
languages: DotISOItem[];
}
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
export * from './lib/resolvers/dot-locales-list.resolver';

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
class="locales-list__search"
(input)="dt.filterGlobal($event.target.value, 'contains')"
type="text"
data-testId="input-search"
pInputText />
</span>
<button
Expand Down Expand Up @@ -53,3 +54,6 @@
</ng-template>
</p-table>
</ng-container>

<p-confirmDialog [key]="dialogKey" [style]="{ width: '30vw' }" />
<p-toast></p-toast>
Loading

0 comments on commit 886ffe4

Please sign in to comment.