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

Qubitro Integration #1251

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/img/channels/community/qubitro.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 15 additions & 3 deletions assets/js/components/channels/ChannelConnectionDetails.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import GoogleSheetForm from "./community/google_sheets/GoogleSheetUpdateForm.jsx
import MicroshareForm from "./community/microshare/MicroshareUpdateForm.jsx";
import TagoForm from "./community/tago/TagoUpdateForm.jsx";
import UbidotsForm from "./community/ubidots/UbidotsUpdateForm.jsx";
import QubitroForm from "./community/qubitro/QubitroForm";
const { Panel } = Collapse

function DetailsUpdateWrapper({ handleUpdateDetailsChange, validInput, children, mobile }) {
Expand Down Expand Up @@ -60,7 +61,7 @@ function DetailsUpdateWrapper({ handleUpdateDetailsChange, validInput, children,
)
}

export default ({ channel, handleUpdateDetailsInput, handleUpdateDetailsChange, validInput, mobile}) => {
export default ({ channel, handleUpdateDetailsInput, handleUpdateDetailsChange, validInput, mobile }) => {
switch (channel.type) {
case "aws":
return (
Expand Down Expand Up @@ -117,13 +118,24 @@ export default ({ channel, handleUpdateDetailsInput, handleUpdateDetailsChange,
/>
</DetailsUpdateWrapper>
);
case "qubitro":
return (
<DetailsUpdateWrapper handleUpdateDetailsChange={handleUpdateDetailsChange} validInput={validInput} mobile={mobile}>
<QubitroForm
onValidInput={handleUpdateDetailsInput}
type="update"
channel={channel}
mobile={mobile}
/>
</DetailsUpdateWrapper>
);
case "cargo":
return (
<div style={{ marginBottom: mobile ? 20 : 0 }}/>
<div style={{ marginBottom: mobile ? 20 : 0 }} />
);
case "my_devices":
return (
<div style={{ marginBottom: mobile ? 20 : 0 }}/>
<div style={{ marginBottom: mobile ? 20 : 0 }} />
);
case "adafruit":
return (
Expand Down
5 changes: 4 additions & 1 deletion assets/js/components/channels/ChannelNew.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import MobileLayout from "../mobile/MobileLayout";
import ArrowLeftOutlined from "@ant-design/icons/ArrowLeftOutlined";
import { CORE_INTEGRATION_TYPES, COMMUNITY_INTEGRATION_TYPES, getAllowedIntegrations } from "../../util/integrationInfo";
import { isMobile } from "../../util/constants";
import QubitroForm from "./community/qubitro/QubitroForm";

@connect(null, mapDispatchToProps)
class ChannelNew extends Component {
Expand All @@ -42,7 +43,7 @@ class ChannelNew extends Component {
const allowedIntegrations = getAllowedIntegrations()
const { search } = this.props.history.location
const searchParams = search.split("?type=")
if ( searchParams[1] && find(COMMUNITY_INTEGRATION_TYPES.filter(i => allowedIntegrations[i.type]), {type: searchParams[1]}) ) {
if (searchParams[1] && find(COMMUNITY_INTEGRATION_TYPES.filter(i => allowedIntegrations[i.type]), { type: searchParams[1] })) {
this.setState({ type: searchParams[1] })
}
}
Expand Down Expand Up @@ -82,6 +83,8 @@ class ChannelNew extends Component {
return <GoogleSheetForm from="ChannelNew" mobile={mobile} type={type} reset={this.resetType} createChannel={this.props.createChannel} />
case "microshare":
return <MicroshareForm mobile={mobile} type={type} reset={this.resetType} createChannel={this.props.createChannel} />
case "qubitro":
return <QubitroForm mobile={mobile} type={type} reset={this.resetType} createChannel={this.props.createChannel} />
default:
return <CommonForm mobile={mobile} type={type} reset={this.resetType} createChannel={this.props.createChannel} />
}
Expand Down
82 changes: 82 additions & 0 deletions assets/js/components/channels/community/qubitro/QubitroForm.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import React, { Component } from "react";
import { Typography, Input } from "antd";
const { Text } = Typography;

class QubitroForm extends Component {
state = {
webhookKey: "",
projectId: "",
appName: "",
};

componentDidMount() {
const { channel } = this.props;

if (channel) {
this.setState({
appName: channel.qubitro_app_name,
webhookKey: channel.qubitro_webhook_key,
projectId: channel.qubitro_projectId,
});
}
}

handleInputUpdate = (e) => {
this.setState({ [e.target.name]: e.target.value }, () => {
const { webhookKey, projectId, appName } = this.state;

this.props.onValidInput({
qubitro_webhook_key: webhookKey,
qubitro_projectId: projectId,
qubitro_app_name: appName,
}, webhookKey.length > 0 && projectId.length > 0 && appName.length > 0);
});
};

render() {
return (
<div>
<div style={{ marginTop: "20px" }}>
<Text style={{ display: "block" }}>Webhook Signing Key</Text>
<Input
placeholder=""
name="webhookKey"
value={this.state.webhookKey}
onChange={this.handleInputUpdate}
style={{
marginBottom: "10px",
width: "100%",
}}
/>
<br />
<Text style={{ display: "block" }}>Project ID</Text>
<Input
placeholder=""
name="projectId"
value={this.state.projectId}
onChange={this.handleInputUpdate}
style={{
marginBottom: "10px",
width: this.props.mobile ? "100%" : "350px",
}}
/>
<br />
<Text style={{ display: "block" }}>App Name</Text>
<Input
placeholder=""
name="appName"
value={this.state.appName}
onChange={this.handleInputUpdate}
style={{
marginBottom: "10px",
width: this.props.mobile ? "100%" : "350px",
}}
/>
<br />
</div>
</div>
);
}
}

export default QubitroForm;
18 changes: 17 additions & 1 deletion assets/js/util/integrationInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,16 @@ import TagoDark from "../../img/channels/community/flows/tago-dark.png";
import Ubidots from "../../img/channels/community/ubidots.png";
import UbidotsDark from "../../img/channels/community/flows/ubidots-dark.png";
import UbidotsIntro from "../../img/channels/community/intro_screens/ubidots.png";
import Qubitro from "../../img/channels/community/qubitro.png";
import QubitroDark from "../../img/channels/community/flows/qubitro-dark.png"
import QubitroIntro from "../../img/channels/community/intro_screens/qubitro.png";

export const integrationImgMap = {
adafruit: AdafruitDark,
aws: AwsDark,
azure: AzureDark,
iot_central: IotCentralDark,
qubitro: QubitroDark,
cargo: CargoDark,
my_devices: MyDevicesDark,
datacake: DatacakeDark,
Expand All @@ -49,7 +53,7 @@ export const integrationImgMap = {
akenza: AkenzaDark,
};

export const http_integrations = ["http", "cargo", "my_devices", "akenza", "datacake", "microshare", "tago", "ubidots", "google_sheets"]
export const http_integrations = ["http", "cargo", "my_devices", "akenza", "datacake", "microshare", "tago", "ubidots", "google_sheets", "qubitro"]
export const mqtt_integrations = ["mqtt", "adafruit"]

export const getAllowedIntegrations = () => {
Expand Down Expand Up @@ -231,4 +235,16 @@ export const COMMUNITY_INTEGRATION_TYPES = [
},
introImg: `${UbidotsIntro}`
},
{
name: "Qubitro",
type: "qubitro",
img: `${Qubitro}`,
info: {
title: "The fastest way to ingest data from devices and transform them into actionable information.",
desc: "Qubitro is a device data platform that gives superpowers to innovators to build solutions powered by device data.",
docLink: "https://docs.qubitro.com/data-sources/lorawan/helium-console",
externalLink: "https://www.qubitro.com"
},
introImg: `${QubitroIntro}`
},
];
3 changes: 2 additions & 1 deletion lib/console/channels/channel.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defmodule Console.Channels.Channel do
alias Console.Organizations.Organization
alias Console.Channels.Channel

@http_types ~w(http cargo my_devices akenza datacake microshare tago ubidots google_sheets)
@http_types ~w(http cargo my_devices akenza datacake microshare tago ubidots google_sheets qubitro)
@long_type_names %{
"aws" => "AWS IoT",
"azure" => "Azure IoT Hub",
Expand All @@ -23,6 +23,7 @@ defmodule Console.Channels.Channel do
"ubidots" => "Ubidots",
"google_sheets" => "Google Sheets",
"adafruit" => "Adafruit IO",
"qubitro" => "Qubitro",
}

@primary_key {:id, :binary_id, autogenerate: true}
Expand Down
14 changes: 14 additions & 0 deletions lib/console/community/community_channels.ex
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ defmodule Console.CommunityChannels do
|> Map.put(:endpoint, "https://dataplugin.ubidots.com/api/web-hook/#{channel.credentials["webhook_token"]}")
|> Map.put(:method, "post")
|> Map.put(:headers, Jason.encode!(%{}))
"qubitro" ->
channel
|> Map.put(:endpoint, "https://webhook.qubitro.com/integrations/helium")
|> Map.put(:method, "post")
|> Map.put(:headers, Jason.encode!(%{ "webhookSigningKey" => channel.credentials["qubitro_webhook_key"], "projectId" => channel.credentails["qubitro_projectId"] }))
_ ->
channel
end
Expand Down Expand Up @@ -141,6 +146,15 @@ defmodule Console.CommunityChannels do
"url_params" => %{}
})
|> Map.put(:type, (if show_underlying_type, do: "http", else: channel.type))
"qubitro" ->
channel
|> Map.put(:credentials, %{
"endpoint" => "https://webhook.qubitro.com/integrations/helium",
"headers" => %{ "webhookSigningKey" => channel.credentials["qubitro_webhook_key"], "projectId" => channel.credentails["qubitro_projectId"] },
"method" => "post",
"url_params" => %{}
})
|> Map.put(:type, (if show_underlying_type, do: "http", else: channel.type))
_ ->
channel
end
Expand Down
40 changes: 40 additions & 0 deletions lib/console_web/controllers/v1/channel_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,46 @@ defmodule ConsoleWeb.V1.ChannelController do
end
end

def create(conn, %{ "name" => name, "type" => "qubitro", "qubitro_webhook_key" => qubitro_webhook_key, "qubitro_projectId" => qubitro_projectId, "qubitro_app_name" => qubitro_app_name } = attrs) do
current_organization = conn.assigns.current_organization
allowed_types = Channel.get_allowed_integration_types()

if "qubitro" in allowed_types do
channel_params =
%{
"credentials" => %{
"qubitro_webhook_key" => qubitro_webhook_key,
"qubitro_projectId" => qubitro_projectId,
"qubitro_app_name" => qubitro_app_name
},
"name" => name,
"type" => "qubitro",
"organization_id" => current_organization.id
}

with {:ok, %Channel{} = channel} <- Channels.create_channel(current_organization, channel_params) do
channel =
channel
|> Map.put(:devices, [])
|> Map.put(:labels, [])

AuditActions.create_audit_action(
current_organization.id,
"v1_api",
"channel_controller_create",
channel.id,
attrs
)

conn
|> put_status(:created)
|> render("show.json", channel: channel)
end
else
{:error, :bad_request, "This integration type is not allowed on this Console" }
end
end

def create(conn, %{ "name" => name, "type" => "mqtt", "endpoint" => endpoint, "uplink_topic" => uplink_topic, "downlink_topic" => downlink_topic } = attrs) do
current_organization = conn.assigns.current_organization
allowed_types = Channel.get_allowed_integration_types()
Expand Down