Front-End for the RESTful implementation of Texta Toolkit

Overview

TEXTA

This project was generated with Angular CLI version 7.3.8.

Configuration

Configuration properties

Name Description
apiHost texta-rest API Host (ex: http://localhost:8000)
apiBasePath Base URL to which the endpoint paths are appended (ex: /api/v2)
annotatorUrl URL for the annotator-client, when set, a button linking to the URL is displayed under Annotator
logging Whether the API requests should be logged into the browser console (ex: true)
fileFieldReplace Used in the Searcher table view: Elasticsearch field name, where the contents are displayed as a file link: apiHost/field_content
useCloudFoundryUAA If enabled allows logging in via UAA
uaaConf Variables for the uaa deploy, more info here

Configuration in Production

Frontend makes a get request to /assets/config/config.json to retrieve the configuration file.

Configuration in Development

Configuration template files are located under /src/configurations/

Currently there are 3 different types of configuration templates:

  1. Cypress - Only used in gitlab ci
  2. Dev - Used when you run the development server locally (ng serve)
  3. Prod - Example configuration file to copy into the /dist/assets/config/ directory upon building the project (ng build) This file is named config.json.example to avoid overwriting an already existing configuration file in a production environment so you need to make the config.json file yourself

The Configuration template file is chosen based on the build flags and then copied over to the /dist/assets/config/ folder. This allows for changing the configuration variables even after we've built our project.

Development server

Run ng serve for a dev server. Navigate to http://localhost:4200/. The app will automatically reload if you change any of the source files.

Code scaffolding

Run ng generate component component-name to generate a new component. You can also use ng generate directive|pipe|service|class|guard|interface|enum|module.

Build

Run ng build to build the project. The build artifacts will be stored in the dist/ directory. Use the --prod flag for a production build.

Running unit tests

Run ng test to execute the unit tests via Karma.

Running end-to-end tests

Run npm run cypress:open to execute the end-to-end tests via Cypress.

Further help

To get more help on the Angular CLI use ng help or go check out the Angular CLI README.

Tutorial on creating a new Model app

In this example, functionality for TorchTagger is created.

In order to start the new app, you first need need to create a Module.

  • Run ng g m torch-tagger/torch-tagger --routing=true to create torch-tagger.module.ts and torch-tagger-routing.module.ts

  • Within torch-tagger.module.ts, in the array of imports, import SharedModule, and remove the default CommonModule import.

  • Make sure TorchTaggerModule is included in the imports array in app.module.ts

Now a component that will be declared in TorchTaggerModule can be created

  • Run ng g c torch-tagger/torch-tagger --module torch-tagger/torch-tagger to create a component, that will be automatically declared in the TorchTaggerModule.

In order for us to navigate to that component, we need to set up routing for it.

Set up the Routing module

  • In torch-tagger-routing.module.ts routes array, add a new object: { path: 'torchtaggers', canActivate: [AuthGuard], component: TorchTaggerComponent }
  • path is the url segment you will route to.
  • canActivate is for the Route Guard, to prevent users navigating on the given route in certain conditions. Here, the AuthGuard Route Guard is added, to make the route only accessible to logged in users.
  • component is the component that gets activated when the user is on that route.

Add a way to navigate to the component

  • In navbar.component.html find the mat-menu with the #models template reference variable and add a new element, with [routerLink]="['torchtaggers']"

Now when we open the Models menu, the new item should show up there. When clicked, it should navigate us to the torchtagger component, which should say something like "torch-tagger-component works!"

Create a data model if necessary

The TorchTagger will have a data model/interface, to predefine its fields and their types (Its recommended to check other tasks types such as Tagger)

  • Create /shared/types/tasks/TorchTagger.ts
  • There export a class containing the fields and their types

Adding functionality to the component

This component will include a mat table, which means it will include some specific variables that you're better off copy pasting some other component's code, such as tagger.components.ts. It might need changing based on the data you will have in the table.

  • Check over the displayedColumns variable. Its an array of strings that should describe the field values that will be displayed in the table. In order to sort the data, the strings should be django-filter based, eg author__username and task__status will be later used in query parameters for ordering, such as &ordering=author__username
  • In case of copy pasting, make sure to replace the Types with the Type you create, if necessary

Adding template code to the component

Its probably better to copy paste this from something else, such as Tagger as well, and change it to your needs

  • Make sure the ng-container elements that have a matColumnDef directive on them match with your displayedColumns

Adding a dialog component to the component

In case there is a need for a dialog component, it has a few differences with regular components.

  • Create a new component torch-tagger/create-torch-tagger-dialog --module torch-tagger/torch-tagger
  • Add the component to the entryComponents array in @NgModule decorator. If that array is missing, just create it. Eg, put entryComponents: [CreateTorchTaggerDialogComponent] after the imports: [...], array

Working with the dialog componenet

Although compared to regular components there isn't much of a difference, its still better to check other dialog components to see how they work.

Mainly:

  • In create-torch-tagger-dialog.component.ts, put private dialogRef: MatDialogRef<CreateTorchTaggerDialogComponent>, into the constructor parameters, to get a reference variable to the dialog you're in.
  • Now you can control the dialog programmatically, such as closing it with this.dialogRef.close();
  • In order to open the dialog, in torch-tagger.component.ts, you need to import public dialog: MatDialog, in the constructor, and call this.dialog.open(CreateTorchTaggerDialogComponent) to open the dialog.
  • In case your dialog needs data, in the dialog component, inject the data into the constructor, with @Inject(MAT_DIALOG_DATA) public data: { exampleNumber: number; }
  • Pass data to the component by passing additional data to the this.dialog.open call, eg this.dialog.open(CreateTorchTaggerDialogComponent, {data: {exampleNumber: 5}})

Making HTTP calls/requests

In order to make requests, the call logic should be isolated in a service file. Its recommended to just follow the pattern that other service files have

  • Run ng g s torch-tagger/torch-tagger to create torch-tagger.service.ts
  • Create a method for each request method you'll make.
  • To call requests in the torch-tagger.component.ts file, import the service in the constructor with private torchTaggerService: TorchTaggerService
  • Then subscribe to the method you created in the service, eg this.torchTaggerService.getTorchTaggers(currentProjectId).subscribe((torchTaggers: Torchtagger) => { console.log(torchTaggers) })
  • Its recommended to take a look at the rxjs docs

Making the default tests work

Tests are in .component.spec.ts files, and you can call tests with ng test. Note: you might need to have Google Chrome installed. By default, tests are missing certain imports that you may need.

For regular component tests:

  • In torch-tagger.service.spec.ts, add {imports: [...]} to the TestBed.configureTestingModule() arguments
  • The imports array should (probably) include RouterTestingModule, SharedModule, HttpClientTestingModule, BrowserAnimationsModule, depending on what functionality your component has
  • Check over the tests for the service file as well

You can always use tests of other components as examples

For dialog tests:

Dialog tests require some additional configuration

  • Add let fixture: ComponentFixture<CreateTorchTaggerDialogComponent>;
  • and const mockDialogRef = { close: jasmine.createSpy('close') }; as class variables
  • Import the necessary files, and add a providers array to configureTestingModule, which includes { providers: [ { provide: MatDialogRef, useValue: mockDialogRef }]}
  • In case your dialog has data, also create some mock data as a class variable, eg const data = {currentProjectId: 1, taggerId: 2};
  • Use provide that data by adding an additional provider to the providers list { provide: MAT_DIALOG_DATA, useValue: data }]
You might also like...

MiniSense RESTful API

MiniSense RESTful API Why was it developed This project is part of an activity proposed by SenseUp aimed at approving a selection process for a Back-E

Jan 21, 2022

RESTful service to provide API linting as-a-service

API Linting Service Prerequisites / general idea General idea behind this API implementation is to provide an API as a service based on the awesome sp

Mar 14, 2022

🎵 simple and RESTful API for getting lyrics of any song made using Next.js and ChakraUI.

🎵 simple and RESTful API for getting lyrics of any song made using Next.js and ChakraUI.

playground . guide . discord Overview Lyrist is a simple yet powerful RESTful API for getting lyrics of any song using song name and it's artist name.

Dec 17, 2022

A dockerized uptime monitoring RESTful API server that allows authenticated users to monitor URLs

A dockerized uptime monitoring RESTful API server that allows authenticated users to monitor URLs, and get detailed uptime reports about their availability, average response time, and total uptime/downtime.

Oct 7, 2022

A focused RESTful server framework for Deno 🌰🦕

acorn Rapidly develop and iterate on RESTful APIs using a strongly typed router designed for Deno CLI and Deno Deploy. import { Router } from "https:/

Dec 10, 2022

Here's a RESTful API that interacts with a PostgreSQL database written in NodeJS with Typescript, RESTify, and Sequelize ORM.

Here's a RESTful API that interacts with a PostgreSQL database written in NodeJS with Typescript, RESTify, and Sequelize ORM.

Basic description REST (Representational State Transfer) is a standard architecture for building and communicating with web services, It typically man

Jan 14, 2022

Uptime monitoring RESTful API server that allows authenticated users to monitor URLs, and get detailed uptime reports about their availability, average response time, and total uptime/downtime.

Uptime Monitoring API Uptime monitoring RESTful API server that allows authenticated users to monitor URLs, and get detailed uptime reports about thei

Jun 14, 2022

A RESTful API for Bing wallpaper to use easy.

A RESTful API for Bing wallpaper to use easy.

bing-wallpaper A RESTful API for Bing wallpaper to use easy. img src="https://bingw.jasonzeng.dev/?w=800"/ Usage API Endpoint: https://bingw.jasonze

Dec 15, 2022

A RESTful API to support online store.

A RESTful API to support online store.

📝 Table of Contents About API Endpoint Get started Installation Running Building for production Running Tests Technology Contributors License 📙 Abou

Dec 17, 2022
Owner
TEXTA
AI-powered text analytics for the online world
TEXTA
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
A front-end only implementation of linked template cards for Lovelace

Linked Lovelace by @daredoes A Javascript/Websocket way to do templating in the Lovelace UI Support Hey you! Help me out for a couple of ?? or a ☕ ! F

Daniel Evans 13 Dec 12, 2022
RESTful API using Hapi NodeJs Framework. This app is project from Dicoding Couses, Belajar Membuat Aplikasi Back-end untuk Pemula

RESTful API using Hapi NodeJs Framework. This app is project from Dicoding Couses, Belajar Membuat Aplikasi Back-end untuk Pemula

Muhammad Ferdian Iqbal 1 Jan 3, 2022
Personal Blog - a project developed with Angular for the front-end interface and Wordpress for the back-end API served with Docker containers

PersonalBlog This project was generated with Angular CLI version 13.0.1. Front-end Interface Development server Run ng serve or ng serve --configurati

null 9 Oct 5, 2022
Pass trust from a front-end Algorand WalletConnect session, to a back-end web service

AlgoAuth Authenticate to a website using only your Algorand wallet Pass trust from a front-end Algorand WalletConnect session, to a back-end web servi

Nullable Labs 16 Dec 15, 2022
It consists of a recreation of Twitter, to put into practice both Front-end and Back-end knowledge by implementing the MERN Stack together with other technologies to add more value to the project.

Twitter-Clone_Back-end ✨ Demo. ?? About the project. ?? Descriptions. It consists of a recreation of Twitter, to put into practice knowledge of both F

Mario Quirós Luna 5 Apr 12, 2022
It consists of a recreation of Twitter, to put into practice knowledge of both Front-end and Back-end implementing the MERN Stack along with other technologies to add more value to the project.

Twitter-Clone_Front-end ✨ Demo. Login Home Profile Message Notifications Deployed in: https://twitter-clone-front-end.vercel.app/ ?? About the project

Mario Quirós Luna 5 Jun 26, 2022
Web-Technology with Aj Zero Coding. In this tutorial we learn front-end and back-end development.

Installation through NPM: The jQWidgets framework is available as NPM package: jQuery, Javascript, Angular, Vue, React, Web Components: https://www

Ajay Dhangar 3 Nov 19, 2022
Lolis-rest - RESTful API for lolis-api

Lolis REST RESTful + Website for Lolis API. Introduction This is a RESTful API which will be used on Lolis API Website and Wrapper. This API uses Imgu

Waifu.sbs 3 Aug 11, 2022