-
Notifications
You must be signed in to change notification settings - Fork 17
Add-readme-to-vuejs-getting-started #406
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
Merged
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
71e7e38
add getting started vuejs
berthieresteban 71b2b69
add readme
berthieresteban 44e46e0
Merge remote-tracking branch 'origin/poc-documentation-v6' into add-v…
xbill82 3a0883e
Merge branch 'add-vuejs-getting-started' into add-readme-to-vuejs-get…
xbill82 f2c868f
Update doc/6/getting-started/vuejs/without-vuex/index.md
berthieresteban 09c14a6
Update doc/6/getting-started/vuejs/without-vuex/index.md
berthieresteban 05e8277
Update doc/6/getting-started/vuejs/without-vuex/index.md
berthieresteban 62172da
add last section to readme
berthieresteban c38aa72
Update doc/6/getting-started/vuejs/without-vuex/index.md
berthieresteban fbc6345
Merged changed from 6-dev
xbill82 3ab9158
Merge branch 'add-readme-to-vuejs-getting-started' of github.com:kuzz…
xbill82 ea94f03
Update doc/6/getting-started/vuejs/without-vuex/index.md
berthieresteban b7f5634
Update doc/6/getting-started/vuejs/without-vuex/index.md
berthieresteban 7fa503f
Update doc/6/getting-started/vuejs/without-vuex/index.md
berthieresteban 790c64d
Update doc/6/getting-started/vuejs/without-vuex/index.md
berthieresteban 945e4af
Update doc/6/getting-started/vuejs/without-vuex/index.md
berthieresteban fbdfa88
Update doc/6/getting-started/vuejs/without-vuex/index.md
berthieresteban cb2b8c4
Update doc/6/getting-started/vuejs/without-vuex/index.md
berthieresteban 5ff2e65
Merge remote-tracking branch 'origin/poc-documentation-v6' into add-r…
xbill82 e176114
Merge branch 'add-readme-to-vuejs-getting-started' of github.com:kuzz…
xbill82 ce49db5
Merge branch '6-dev' into add-readme-to-vuejs-getting-started
xbill82 929b6f4
add link to sdk repo
berthieresteban 3be8feb
Merge branch 'add-readme-to-vuejs-getting-started' of github.com:kuzz…
berthieresteban 62d8c09
specify repo
berthieresteban 979ff9c
Merge branch '6-dev' into add-readme-to-vuejs-getting-started
xbill82 19db2fc
Merge branch 'add-readme-to-vuejs-getting-started' of github.com:kuzz…
xbill82 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
87 changes: 87 additions & 0 deletions
87
doc/6/getting-started/vuejs/cypress/integration/tchat.spec.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
describe('test realtime tchat', () => { | ||
let currentIt = 1; | ||
let env; | ||
|
||
before(() => { | ||
cy.initialisation(); | ||
}); | ||
|
||
beforeEach(() => { | ||
cy.visit('/'); | ||
cy.fixture(`Environment.${currentIt}.json`) | ||
.then((fixtures) => { env = fixtures; }) | ||
.then(() => cy.log(`Environment ${currentIt}: `, env)) | ||
.then(() => cy.loadEnvironment(env)); | ||
cy.wait(2000); | ||
}); | ||
|
||
afterEach(() => { | ||
currentIt++; | ||
}); | ||
|
||
it('should enter a nickname', () => { | ||
cy.get('[placeholder="Enter your message"]') | ||
.should('not.exist'); | ||
|
||
cy.get('[placeholder="Enter your nickname"]') | ||
.type(env.username); | ||
|
||
|
||
cy.contains('Valid') | ||
.click(); | ||
|
||
cy.get('[placeholder="Enter your message"]') | ||
.should('exist'); | ||
cy.get('[placeholder="Enter your nickname"]') | ||
.should('not.exist'); | ||
}); | ||
|
||
it('should fetch and display some messages', () => { | ||
cy.get('[placeholder="Enter your nickname"]') | ||
.type(env.username); | ||
cy.contains('Valid') | ||
.click(); | ||
|
||
env.messages.forEach(message => { | ||
cy.get(message.payload.username === env.username ? '.fromMe': '.fromOthers') | ||
.within(() => { | ||
cy.contains(message.payload.value); | ||
cy.contains(message.payload.username); | ||
}); | ||
}); | ||
}); | ||
|
||
it('should send a message', () => { | ||
cy.get('[placeholder="Enter your nickname"]') | ||
.type(env.username); | ||
cy.contains('Valid') | ||
.click(); | ||
cy.createMessage({ | ||
_id: '1', | ||
payload: env.payload | ||
}); | ||
|
||
cy.get('.fromMe') | ||
.within(() => { | ||
cy.contains(env.payload.value); | ||
cy.contains(env.username); | ||
}); | ||
}); | ||
|
||
it('should receive a message', () => { | ||
cy.get('[placeholder="Enter your nickname"]') | ||
.type(env.username); | ||
cy.contains('Valid') | ||
.click(); | ||
cy.createMessage({ | ||
_id: '1', | ||
payload: env.payload | ||
}); | ||
|
||
cy.get('.fromOthers') | ||
.within(() => { | ||
cy.contains(env.payload.value); | ||
cy.contains(env.payload.username); | ||
}); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
code: false | ||
type: branch | ||
title: VueJS | ||
description: Get started with the Javascript SDK and VueJS | ||
order: 300 | ||
--- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
--- | ||
type: page | ||
code: false | ||
title: Without Vuex | ||
description: Getting started with Kuzzle and VueJS | ||
order: 0 | ||
--- | ||
|
||
|
||
# Getting Started with Kuzzle and VueJS | ||
|
||
This section deals with **Kuzzle** (+ **Javascript SDK**) and **VueJS**. We will create **documents** in Kuzzle and subscribe to [document notifications](/sdk/js/6/essentials/realtime-notifications/#document-messages) to develop a realtime chat. | ||
|
||
You can find the full code of this guide [here](https://github.com/kuzzleio/sdk-javascript/tree/6-dev/doc/6/getting-started/vuejs/without-vuex). | ||
|
||
## Requirements | ||
|
||
- **Node.js** >= 8.0.0 ([install here](https://nodejs.org/en/download/)) | ||
- **Vue CLI** ([install here](https://cli.vuejs.org/guide/installation.html)) | ||
- **Running Kuzzle Stack** ([instructions here](/core/1/guides/getting-started/running-kuzzle/)) | ||
|
||
## Prepare your environment | ||
|
||
Create your VueJS app with Vue CLI. You'll need to select manually the features, | ||
just add Babel, Linter and select the default options for the other features. | ||
```bash | ||
vue create kuzzle-playground | ||
``` | ||
|
||
Install the kuzzle-sdk: | ||
```bash | ||
cd kuzzle-playground | ||
yarn add kuzzle-sdk | ||
``` | ||
|
||
In the _App.vue_ file, you should remove the tag, the import and the component registration of the `HelloWorld` component, we won't use it. | ||
|
||
## Instanciating Kuzzle SDK | ||
|
||
We have to connect the server so that our client can interact with it. | ||
|
||
To do this, we have to create _src/services/kuzzle.js_ file to put our kuzzle instance, a bit like a singleton: | ||
|
||
<<< ./src/services/kuzzle.js | ||
|
||
We need to import our Kuzzle SDK instance, so just add the following line in your `<script>` tag in the _App.vue_ file: | ||
|
||
<<< ./src/App.vue:3[js] | ||
|
||
Then we will [etablish the connection](/sdk/js/6/core-classes/kuzzle/connect/) to kuzzle and create, if they don't [exists](sdk/js/6/controllers/index/exists/), the [index](sdk/js/6/controllers/index/create/) and [collection](sdk/js/6/controllers/collection/create/) of our chat. | ||
Add the following `valid()` method in the export of the `<script>` tag of your _App.vue_ file: | ||
|
||
<<< ./src/App.vue:2[js] | ||
|
||
## Get the username | ||
First of all, we need to know the user nickname. Let's start by adding the following html code in the `<template>` tag to allow the client type his nickname: | ||
|
||
<<< ./src/App.vue:1[html] | ||
|
||
As you can see we'll need two properties: `username` and `validate`. | ||
|
||
|
||
## Display the messages | ||
|
||
We'll need some properties to manage our messages. Add the following `data` to your _App.vue_ | ||
|
||
<<< ./src/App.vue:4[js] | ||
|
||
Then, create the following functions to fetch and display the messages: | ||
|
||
<<< ./src/App.vue:5[js] | ||
|
||
<<< ./src/App.vue:6[js] | ||
|
||
The function `fetch_message()` will [search](/sdk/js/6/controllers/document/search/) for the first hundred newest messages and store them in our array before subscribe to notification about `messages` collection. We called it in the `valid()` function we created before. | ||
|
||
<<< ./src/App.vue:7[js] | ||
|
||
Now, just add the following html code to display the messages: | ||
|
||
<<< ./src/App.vue:8[html] | ||
|
||
To finish this part, just add the following css classes: | ||
|
||
<<< ./src/App.vue:9[css] | ||
|
||
We can now display the messages stored in Kuzzle. Cool but we need to create some right ? | ||
|
||
## Send messages | ||
|
||
We need to write a simple method that will [create](/sdk/js/6/controllers/document/create/) a new message document in Kuzzle. | ||
|
||
<<< ./src/App.vue:10[js] | ||
|
||
As you can see we don't push the new message in our array on message creation. | ||
Actually, We'll subscribe to the collection that contains our messages. | ||
So let's create our `subscribe_messages()` action. It will call the realtime controller of Kuzzle to allow us to [receive notifications](/sdk/js/6/controllers/realtime/subscribe/) on message creation: | ||
|
||
<<< ./src/App.vue:11[js] | ||
|
||
To finish, just add an input field, bond to the `message` property and a button which calls our `sendMessage()` function: | ||
|
||
<<< ./src/App.vue:12[html] | ||
|
||
And the following CSS class: | ||
|
||
<<< ./src/App.vue:13[css] | ||
|
||
You can now add new messages to Kuzzle and receive the notification of the creation to update your state and display the new messages, enjoy :) | ||
|
||
You can find the full code of this guide [here](https://github.com/kuzzleio/sdk-javascript/tree/6-dev/doc/6/getting-started/vuejs/without-vuex). | ||
|
||
## Where do we go from here? | ||
|
||
Now that you're more familiar with Kuzzle, dive even deeper to learn how to leverage its full capabilities: | ||
|
||
- discover what this SDK has to offer by browsing other sections of this documentation | ||
- learn more about Kuzzle [realtime engine](/core/1/guides/essentials/real-time/) | ||
- follow our guide to learn how to [manage users, and how to set up fine-grained access control](/core/1/guides/essentials/security/) | ||
- lean how to use Kuzzle [Admin Console](/core/1/guides/essentials/admin-console/) to manage your users and data | ||
- learn how to perform a [basic authentication](/sdk/js/6/controllers/auth/login) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better, no?