Adding a JSON Selection directory to Angular Application - json

So I'm designing a program that lets a user send a JSON to an API using HTTP-Post.
The Json are stored in a folder inside my application called JsonFiles then inside this folder are then put into there own brand name so the path looks something like this >JsonFiles>Nike>OrderConfirm.Json
What would be a good way to let the user select a JSON File from the user interface in like a dropdown menu?
What I have so far is being able to pick a specific file from the component.ts using import,
but this is no good due to I need user interaction to choose the file. In case anyone is wondering I'm creating an application for work.
Thanks guys so much.

You can move these json files to the assets folder. So it will be available to fetch using http request.
httpClient.get(`/JsonFiles/Nike/${jsonFileName}.json`)
And in the component you just need to keep the file names.
files = ['OrderConfirm']
You can also just keep your folder anywhere, But add that path to angular.json as follows,
"assets": [
"src/assets",
"src/favicon.ico"
]
For ref: https://github.com/angular/angular-cli/wiki/stories-asset-configuration

Related

Best practices for creating and reading app configuration file for angular app

I have an angular application that is gona be installed on many sites (owner requeriment) but, for every site, the configuration must be different (colors, some texts, some logos, backend server, etc). I want to write a configuration file that will be read by the angular app and then apply that configuration, I will put the file in every site and when I make a change to the backend server, any configuration text or other configuration I will only change the configuration file and the angular app will work transparently.
How can I achieve this?
I was thinking in writing a json file and read it from angular. Is this a good practice?
you can use 'environment.ts' for your problem.
but I use 'environment.ts' or 'environment.prod.ts' for the Variables that have different value in product and develop mode.
for values like store/app/crm name, simply you can add 'ts' file like 'myAppConfig.ts' in 'src' folder or 'app' folder.
then declare your variables like this:
export const myAppConfig = {
appName:'samuels online store',
expireDate:'2023/30/12',
customerName:'samuel l jackson'
};
then you can use it,like this:
first import it in your 'ts' file, for example in 'app.component.ts'.
import { myAppConfig } from 'src/myAppConfig';
then use the values of it, like this:
customerName = myAppConfig.clientName;
finally, you can put or change values in 'myAppConfig' from your backend and give a fresh version to your new customers.
have a good time!

How can I use a Liquid-generated JSON as a "_data" site.data object in Jekyll?

Using Liquid, I am trying to build a JSON object (skills.json) containing data from all of my Jekyll posts.
When I place this file in my _data folder in my project root directory per https://jekyllrb.com/docs/datafiles/, trying to access the data via site.data.skills with the inspect filter or console log resolves to nothing.
final output section of my Liquid json
When I instead place my skills.json file in the /assets/js/ folder in my root, I do see that the properly populated JSON file is added to my _site folder as expected. Copying this NEW file into the root _data folder successfully populates to my page as intended, and I am able to access all the data with site.data.skills.KEY.
json generated from assets folder at build time
Is there any way that I could specify that the generated skills.json in my /assets/js/ folder be the source for my data call?
Alternatively, is there a way to generate the final data and automatically move it to the _data folder ahead of building the site? I am open to any suggestions for how to automate this. As a warning, I am pretty new to web development in general, so any references or links would be a tremendous help. Thanks!
Following up on this, I believe that the issue lies in how the site is built. The skills.json file gets generated on the first build, and then when it is added to the _data folder, the site gets built AGAIN to update everything that hits that data. With this iterative process, I don't know if it would be possible to both generate the new file and use it as a source to update everything dependent on the data in the same pass.
As far as automating goes, my thinking is that a Ruby plugin to compare the newly generated files against the _data folder and overwrite if the source is different/newer would be the way to go, but I'm still open to any suggestions!

Export from Sketch App to JSON

I want to be able to export Layer Names and properties from Sketch to JSON format. I think I can figure out how to pull the info I need from Sketch, but I haven't started to code anything, because I haven't been able to find any info about this export issue.
I'm wondering if anyone can help confirm that Sketch can only export their supported formats or if export to JSON is possible. I don't want to dive into this project only to find out that I can't end up with a JSON file.
I have been trying to work with this as well, and it turns out there are a few ways to get access to a JSON file in sketch.
use the npm package sketch2json
Turns out that if you unzip the .sketch file, there is a JSON file hiding inside.
unzip sketch-header.sketch
This creates a folder called 'pages' with the .json file inside. To get the 'Layer Names', you can just read/serialize the .json file into a string, and then the path to collect the layer names is
const obj = JSON.parse(fileString);
object.layers.forEach((layer) => {
console.log(layer.name);
});
If you rename the .sketch extension file to .zip extension file you will see as many JSON files as pages your sketch document has inside a folder called "Pages". Also some BMP previews images and other JSON related to user and document information.

Swagger API Specification filenames

I'm trying to use Swagger to create API documentation for an API we're building and I've never used it before.
The documentation on Github says that the Resources Listing needs t be at /api-docs and the various resource files need to be at /api-docs/books etc.
This makes naming files and folders very tricky. I think they expect the files to have no file names, rather than having a folder called /api-docs it has to be an extension-less file, then you can't put the resources in an api-docs folder because you can't call the folder that, so they suggest using a folder called /listings.
This folder doesn't appear in the URL structure of your documentation though, it's kind of invisible because you set the baseURL in your resources to the proper path, but it looks like that has to be an absolute path, which is awkward if you want to have it on several servers (local and production).
Maybe I just don't get it but this all seems to be absolutely nuts.
So, I have 2 questions.....
1) Can I give my resource listing file and my resource files a .json extension? This would make sense as it's a JSON file.
2) Can I use a relative path to the resource listing file in the baseURL in my resource files?
Ideally, my file structure would be flatter, like this...
/api-docs
resources.json
books.json
films.json
Is Swagger flexible enough to do this?
It's an IIS server if that makes any difference (if the solution requires routing for example).
I was able to put model files into a folder under the web root and could reference them like this.
$ref: '/models/model.yml#/MyObject'
Relative paths also worked without a leading slash.
$ref: 'models/model.yml#/MyObject'
Inside the model.yml, I can reference other objects int eh same file like this
$ref: '#/MyObject2'.
However, I could only get the main swagger file to import model files. I could not get one model file to cross-reference another model file.
I was using a Tomcat web server but the principle will be the same.

symfony2 store read-only configuration

What is the best way to store read-only configuration in symfony?
I have some name/description pairs inside a JSON file, currently sitting in a bundle's resource directory that I'd like to use inside my controllers and views but don't want to insert into my database.
And what do you recommend for parsing / getting the values to display? Making a specific service for the DiC doesn't feel to good tbh..
Same scenario with me ,I worked with ymls file , create a yml file in config folder like product.yml , parse it in controller then send its josn to template .
And this is the right way to play with static data .