cockpit_client

Creator: coderz1093

Last updated:

0 purchases

cockpit_client Image
cockpit_client Images

Languages

Categories

Add to Cart

Description:

cockpit client

Client for cockpit CMS #
A http-client for your Cockpit CMS content.
How Install #
Flutter: #
$ flutter pub add cockpit_client
copied to clipboard
Pubspec.yaml #
Add a line like this to your package's pubspec.yaml
dependencies:
cockpit_client: ^1.0.6-b
copied to clipboard
And run if your editor don't support flutter
flutter pub get
copied to clipboard
And import it #
Now in your Dart code, add
import 'package:cockpit_client/cockpit_client.dart';
copied to clipboard
How Initialize #

Minimal #
import 'package:cockpit_client/cockpit_client.dart';

// Minimal Initialisation
Cockpit.init(
server: Uri.parse("http://[SERVER HOST]"),
token: "[API TOKEN]",
);
copied to clipboard
Cocpit is not in root web folder #
import 'package:cockpit_client/cockpit_client.dart';

// Custom path
Cockpit.init(
server: Uri.https("[SERVER HOST]"."/cockpit/folder"),
// OR
//server: Uri.http("[SERVER HOST]"."/cockpit/folder"),
// OR
//server: Uri.parse("http://[SERVER HOST]/cockpit/folder"),
token: "[API TOKEN]",
);
copied to clipboard
Filter for all request #
import 'package:cockpit_client/cockpit_client.dart';

// never get deleted fields
Cockpit.init(
server: Uri.https("[SERVER HOST]"."/cockpit/folder"),
token: "[API TOKEN]",
defaultFilter : {
r"$or" :[
{ "delete" : {$eq : false} },
{ "delete" : {$eq : null} },
{
"delete" : {
r"$exist" : false
}
}
]
}
);
copied to clipboard
(Optional) Declare endpoint #
import 'package:cockpit_client/cockpit_client.dart';

// Api declaration
Cockpit.init(
server: Uri.https("[SERVER HOST]"."/cockpit/folder"),
token: "[API TOKEN]",
api : {
// Collection
"myCollection" : {
"collection": "users", // real collection name
"sort": {"login": 1}, // default sort
"fields": [ // get only this fields
"nom",
"prenom",
"parent",
"login",
"enabled",
"_create_by"
]
},
// Form
"myForm" : {
"form": "sendmail" // real form name
},
// Singleton
"mySingleton" : {
"singleton": "configurations" // real singleton name
},
// clollection with virtual properties (map)
"slides" : {
"collection": "collection_name", //collection name in cockpit
"limit": 5, // limit when get data from server
"sort": { // sort results
"_o": 1
},
"fields": [ // fields to gets from the server, other will be ignored
"title",
"image",
"description",
"backgroundColor",
"fontColor"
],
"map": { // change value of a property or set a new property in result object
// you can build string from a template
"image": "{{SERVER}}{{image.path}}",
// or map a property's value to another
"body" : "{{description}}"
},
},
}
);
copied to clipboard
How Use #
Read data #
// get all elements
List<Map<String, dynamic>> results = await Cockpit("api_access").find(
cache: Duration(hours : 1), // [optional] cache result
);

// get first element
Map<String, dynamic> result = await Cockpit("user").findOne(
filter: {
"login" : "root",
"pwd" : "secret",
r"$or": [
{"disable": false},
{
"disable": {
r"$exists": false,
},
},
],
},
);

// get specific element
Map<String, dynamic> result = await Cockpit("user").get("[My Super ID]");
// get only some fields
Map<String, dynamic> result = await Cockpit("user").get("[My Super ID]", fields : ["nom", "prenom"]
);

// get one page of elements
List<Map<String, dynamic>> results = await Cockpit("api_access").find(
limit : 10,
page : 2
); // page start by 0, also set page to 0 for the first page, page to 1 for the second page

// get filtered elements , you can use page, limit, sort, etc. with filter
List<Map<String, dynamic>> results = await Cockpit("api_access").find(
filter: {
published : true,
},
);
copied to clipboard
Read undeclared endpoint #
To read an undelared endpoint you can just pass the name and use a prefix to specify the type (form, singleton,collection or custom url)



Prefix
Type
Usage




*
Collection
Cockpit("my_collection") OR Cockpit("*my_collection")


@
Singleton
Cockpit("@my_singleton")


#
Form
Cockpit("#my_form")


!
Custom Cockpit Api
Cockpit("!my/custom/url")



Save data #
// post data to cockpit (form and collection)
Map<String, dynamic> data = await Cockpit("api_access").save(
data : {
published : false,
title : "Cool",
description : "I'm juste a test :-p",
},
);
copied to clipboard
post to a Custom Url #
// post data to a custom cockpit url
Map<String, dynamic> data = await Cockpit("!/addons/save/gps").get(
data : {
lat : -19.016682,
long : 26.806641,
alt : 15,
},
);
copied to clipboard
Cockpit urls #
Authenticate user #
Cockpit.authUser('username','xxpasswordxx')
copied to clipboard
Create / Update user #
Cockpit.saveUser({...}) // user data (user, name, email, active, group)
copied to clipboard
Get users. #
Cockpit.listUsers([Map<String, dynamic> filter]) // (optional) you can pass filter
copied to clipboard
Get assets #
Cockpit.assets([Map<String, dynamic> filter]) // (optional) you can pass filter
copied to clipboard
Get thumbnail url #
Cockpit.image(imagePath,
width : width,
height : height,
quality : quality,
domain : domain,
o : o,
base64 : base64,
);
copied to clipboard
Get all singletons #
Cockpit.listSingletons()
copied to clipboard
Get all collections #
Cockpit.listCollections();
copied to clipboard
Get collection schema #
Cockpit("collectionname").schema();
copied to clipboard
Update collection schema #
Cockpit("collectionname").updateSchema(fields); // fields is List<Map<String,dynamic>>
copied to clipboard

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.