Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using with Angular #41

Closed
YouNone opened this issue Mar 9, 2021 · 12 comments
Closed

Using with Angular #41

YouNone opened this issue Mar 9, 2021 · 12 comments

Comments

@YouNone
Copy link

YouNone commented Mar 9, 2021

I installed three packages:

"brackets-manager": "^1.2.7",
"brackets-model": "^1.3.5",
"brackets-viewer": "^1.3.1"

But after this operation I could not find a detailed example of the installation. I was able to run the example with db.json and index html file, but that's all.

Therefore, I wanted to know if it can be run under angular and if so, how?

@Drarig29
Copy link
Owner

Drarig29 commented Mar 9, 2021

Yes you can do it, but manually. It's a vanilla library.

You have an example using React here, you can take inspiration from it.

Basically, you need to add the library in your index.html in the public folder.

Once loaded in this file, the library will add a global variable bracketsViewer that you can use directly in your Angular code.

@Drarig29
Copy link
Owner

Drarig29 commented Mar 9, 2021

Currently the manager can't be used in the browser, you need to use it with Node.js, in a back-end.

Edit: apparently you don't have any problem with Angular. (linking with Drarig29/brackets-manager.js#57)

And serving modules from your node_modules is a bad practice, so you should import the viewer with <script> and <link> tags (for JS and CSS).

@YouNone
Copy link
Author

YouNone commented Mar 9, 2021

Thanks for the quick answer, I wanted to clarify if it is possible to access the bracketsViewer variable in a specific component?

I need something like this:

           
import { bracketsViewer } from "brackets-viewer"

export class Component implements OnInit {
    async getData() {
        const manager = new BracketsManager(storage);
        const example = {
                name: 'Example',
                tournamentId: 1,
                type: 'double_elimination',
                seeding: ['Team 1', 'Team 2', 'Team 3', 'Team 4', 'Team 5', 'Team 6', 'Team 7', 'Team 8'],
                settings: { seedOrdering: ['natural'] },
        };

        await manager.create(example);

        const stage = await storage.select('stage', 0);
        console.log(stage);
    }

    ngOnInit() {
        this.getData();
    }
}

And how to display in component-tree.html?

@Drarig29
Copy link
Owner

Drarig29 commented Mar 9, 2021

You don't need to import bracketsViewer in your components.

Add this in your index.html :

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/brackets-viewer/dist/brackets-viewer.min.css" />
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/brackets-viewer/dist/brackets-viewer.min.js"></script>

The library will define a global variable in the window object. So if you prefer, you can access it with window.bracketsViewer.

@Drarig29
Copy link
Owner

Drarig29 commented Mar 9, 2021

After that, adding an empty div in your component-tree.html should do the job:

<div class="bracket-viewer"></div> 

@YouNone
Copy link
Author

YouNone commented Mar 9, 2021

Thanks again for the quick answer, the tree is displayed.

@aydinduygu
Copy link

Thanks again for the quick answer, the tree is displayed.

Hi, do you still have the code for angular? Can you show how did you call the lib in ts file, thanks in advance

@Drarig29
Copy link
Owner

Drarig29 commented Apr 22, 2023

Ping @YouNone

@aydinduygu
Copy link

Hi @Drarig29; I am trying to implement in angular project. Although i have a html element with class name 'brackets-viewer', I am getting this error:
image

It says 'Root not found'. Can you please help me. Thanks in advance

@Drarig29
Copy link
Owner

Which version of the viewer do you use?

@aydinduygu
Copy link

image

Hi again, I just removed this 't' from the code in the lib and problem is fixed (I hope). I have no idea why this works :-). Thanks for your interest

@Drarig29
Copy link
Owner

Drarig29 commented Apr 22, 2023

In your screenshot, t is the name for selector in the minified code. The selector parameter is passed here:

findRoot(config?.selector).append(root);

So you might have a selector property passed in your bracketsViewer.render() call, just like here:

selector: '#example',

And this parameter overrides the default .brackets-viewer selector.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants