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

Add carbon calculator app #9724

Merged
merged 14 commits into from
Jul 26, 2023
Merged
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
6 changes: 6 additions & 0 deletions packages/manager/apps/carbon-calculator/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"globals": {
"__VERSION__": true,
"__NG_APP_INJECTIONS__": true
}
}
72 changes: 72 additions & 0 deletions packages/manager/apps/carbon-calculator/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
"name": "@ovh-ux/manager-carbon-calculator-app",
"version": "0.0.0",
"private": true,
"description": "OVHcloud CarbonCalculator app",
"repository": {
"type": "git",
"url": "git+https://github.com/ovh/manager.git",
"directory": "packages/manager/apps/carbon-calculator"
},
"license": "BSD-3-Clause",
"author": "OVH SAS",
"scripts": {
"build": "webpack --env.production",
"dev": "webpack-dev-server",
"dev:watch": "yarn run dev",
"start": "lerna exec --stream --scope='@ovh-ux/manager-carbon-calculator-app' --include-dependencies -- npm run build --if-present",
"start:dev": "lerna exec --stream --scope='@ovh-ux/manager-carbon-calculator-app' --include-dependencies -- npm run dev --if-present",
"start:watch": "lerna exec --stream --parallel --scope='@ovh-ux/manager-carbon-calculator-app' --include-dependencies -- npm run dev:watch --if-present"
},
"dependencies": {
"@ovh-ux/manager-at-internet-configuration": "^1.5.0",
"@ovh-ux/manager-carbon-calculator": "^0.0.0 || ^1.0.0",
"@ovh-ux/manager-config": "^7.0.0",
"@ovh-ux/manager-core": "^12.0.0 || ^13.0.0",
"@ovh-ux/manager-error-page": "^2.3.1",
"@ovh-ux/manager-ng-layout-helpers": "^2.6.1",
"@ovh-ux/ng-at-internet": "^5.10.2",
"@ovh-ux/ng-at-internet-ui-router-plugin": "^3.2.3",
"@ovh-ux/ng-ovh-api-wrappers": "^5.0.0",
"@ovh-ux/ng-ovh-feature-flipping": "^1.0.7",
"@ovh-ux/ng-ovh-http": "^5.0.0",
"@ovh-ux/ng-ovh-request-tagger": "^1.1.7",
"@ovh-ux/ng-ovh-sso-auth": "^4.6.3",
"@ovh-ux/ng-ovh-swimming-poll": "^5.0.6",
"@ovh-ux/ng-shell-tracking": "^0.2.1",
"@ovh-ux/ng-translate-async-loader": "^2.1.5",
"@ovh-ux/ng-ui-router-breadcrumb": "^1.1.7",
"@ovh-ux/request-tagger": "^0.1.1",
"@ovh-ux/shell": "^2.0.0",
"@ovh-ux/ui-kit": "^6.3.0",
"@uirouter/angularjs": "^1.0.23",
"angular": "^1.7.5",
"angular-aria": "^1.7.8",
"angular-cookies": "^1.7.8",
"angular-dynamic-locale": "^0.1.37",
"angular-i18n": "^1.7.8",
"angular-resource": "^1.7.8",
"angular-sanitize": "^1.7.8",
"angular-translate": "^2.18.1",
"angular-translate-loader-pluggable": "^1.3.1",
"core-js": "^3.6.5",
"flatpickr": "~4.6.3",
"jquery": "^2.1.3",
"lodash-es": "^4.17.15",
"oclazyload": "^1.1.0",
"ovh-api-services": "^16.0.0",
"regenerator-runtime": "^0.13.7",
"whatwg-fetch": "^3.5.0"
},
"devDependencies": {
"@ovh-ux/manager-webpack-config": "^6.1.1",
"glob": "^7.1.6",
"lodash": "^4.17.15",
"webpack": "^4.44.2",
"webpack-merge": "^4.2.2"
},
"regions": [
"CA",
"EU"
]
}
151 changes: 151 additions & 0 deletions packages/manager/apps/carbon-calculator/src/app.module.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
import angular from 'angular';
import get from 'lodash/get';
import has from 'lodash/has';
import isString from 'lodash/isString';
import uiRouter, { RejectType } from '@uirouter/angularjs';
import '@ovh-ux/ui-kit';
import { isTopLevelApplication } from '@ovh-ux/manager-config';
import { registerAtInternet } from '@ovh-ux/ng-shell-tracking';
import { registerCoreModule } from '@ovh-ux/manager-core';
import ngOvhSsoAuth from '@ovh-ux/ng-ovh-sso-auth';
import ngUiRouterBreadcrumb from '@ovh-ux/ng-ui-router-breadcrumb';
import ovhManagerAtInternetConfiguration from '@ovh-ux/manager-at-internet-configuration';
import CarbonCalculator from '../../../modules/carbon-calculator/src';
import errorPage from './error';

import '@ovh-ux/ui-kit/dist/css/oui.css';
import TRACKING from './tracking/at-internet.constants';

export default async (containerEl, shellClient) => {
const moduleName = 'CarbonCalculatorApp';

const routingConfig = /* @ngInject */ ($urlRouterProvider) => {
$urlRouterProvider.otherwise('/billing');
};

const ssoAuthConfig = /* @ngInject */ (ssoAuthenticationProvider) => {
ssoAuthenticationProvider.setOnLogin(() => {
shellClient.auth.login();
});
ssoAuthenticationProvider.setOnLogout(() => {
shellClient.auth.logout();
});
};

const trackingConfig = /* @ngInject */ (atInternetConfigurationProvider) => {
atInternetConfigurationProvider.setSkipInit(true);
atInternetConfigurationProvider.setPrefix('dedicated');
};

const broadcastAppStarted = /* @ngInject */ ($rootScope, $transitions) => {
const unregisterHook = $transitions.onSuccess({}, async () => {
if (!isTopLevelApplication()) {
await shellClient.ux.hidePreloader();
}
$rootScope.$broadcast('app:started');
unregisterHook();
});
};

const [environment, locale] = await Promise.all([
shellClient.environment.getEnvironment(),
shellClient.i18n.getLocale(),
]);

const coreCallbacks = {
onLocaleChange: (lang) => {
shellClient.i18n.setLocale(lang);
},
};

const defaultErrorHandler = /* @ngInject */ ($state) => {
$state.defaultErrorHandler((error) => {
if (error.type === RejectType.ERROR) {
$state.go(
'error',
{
detail: {
message: get(error.detail, 'data.message'),
code: has(error.detail, 'headers')
? error.detail.headers('x-ovh-queryId')
: null,
},
},
{ location: false },
);
}
});
};

const calendarConfigProvider = /* @ngInject */ (
ouiCalendarConfigurationProvider,
) => {
const [lang] = locale.split('_');
return import(`flatpickr/dist/l10n/${lang}.js`)
.then((module) => {
ouiCalendarConfigurationProvider.setLocale(module.default[lang]);
})
.catch(() => {});
};

const transitionsConfig = /* @ngInject */ ($transitions) => {
if (!isTopLevelApplication()) {
$transitions.onBefore({}, (transition) => {
if (
!transition.ignored() &&
transition.from().name !== '' &&
transition.entering().length > 0
) {
shellClient.ux.startProgress();
}
});

$transitions.onSuccess({}, () => {
shellClient.ux.stopProgress();
});

$transitions.onError({}, (transition) => {
if (!transition.error().redirected) {
shellClient.ux.stopProgress();
}
});
}
};

angular
.module(
moduleName,
[
registerCoreModule(environment, coreCallbacks),
registerAtInternet(shellClient.tracking),
ovhManagerAtInternetConfiguration,
ngOvhSsoAuth,
ngUiRouterBreadcrumb,
'oui',
uiRouter,
errorPage,
CarbonCalculator,
...get(__NG_APP_INJECTIONS__, environment.getRegion(), []),
].filter(isString),
)
.constant('shellClient', shellClient)
.config(
/* @ngInject */ ($locationProvider) => $locationProvider.hashPrefix(''),
)
.config(routingConfig)
.config(ssoAuthConfig)
.config(async () => {
await shellClient.tracking.setConfig(environment.getRegion(), TRACKING);
})
.config(trackingConfig)
.config(calendarConfigProvider)
.run(broadcastAppStarted)
.run(transitionsConfig)
.run(defaultErrorHandler);

angular.bootstrap(containerEl, [moduleName], {
strictDi: true,
});

return moduleName;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import managerErrorPage from '@ovh-ux/manager-error-page';

import routing from './error.routing';

const moduleName = 'ovhManagerCarbonCalculatorError';

angular.module(moduleName, [managerErrorPage]).config(routing);

export default moduleName;
21 changes: 21 additions & 0 deletions packages/manager/apps/carbon-calculator/src/error/error.routing.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export default /* @ngInject */ ($stateProvider) => {
$stateProvider.state('error', {
params: {
detail: null,
},
url: '/error',
component: 'managerErrorPage',
resolve: {
cancelLink: /* @ngInject */ ($state) => $state.href('app'),
error: /* @ngInject */ ($transition$) => $transition$.params(),
product: /* @ngInject */ () => 'carbon-calculator',
submitAction: /* @ngInject */ ($window) => () =>
$window.location.reload(),
translationsRefresh: /* @ngInject */ ($translate) => $translate.refresh(),
breadcrumb: () => null,
},
atInternet: {
ignore: true,
},
});
};
22 changes: 22 additions & 0 deletions packages/manager/apps/carbon-calculator/src/error/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import angular from 'angular';
import '@uirouter/angularjs';
import 'oclazyload';

const moduleName = 'ovhManagerCarbonCalculatorErrorPageLazyLoading';

angular.module(moduleName, ['ui.router', 'oc.lazyLoad']).config(
/* @ngInject */ ($stateProvider) => {
$stateProvider.state('error.**', {
url: '/error',
lazyLoad: ($transition$) => {
const $ocLazyLoad = $transition$.injector().get('$ocLazyLoad');

return import('./error.module').then((mod) =>
$ocLazyLoad.inject(mod.default || mod),
);
},
});
},
);

export default moduleName;
16 changes: 16 additions & 0 deletions packages/manager/apps/carbon-calculator/src/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>CarbonCalculator App</title>
<style type="text/css">
.ng-cloak {
display: none !important;
}
</style>
</head>
<body class="container-fluid px-md-5 mt-3">
<ui-router-breadcrumb></ui-router-breadcrumb>
<div data-ui-view></div>
</body>
</html>
26 changes: 26 additions & 0 deletions packages/manager/apps/carbon-calculator/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import 'script-loader!jquery'; // eslint-disable-line
import 'core-js/stable';
import 'whatwg-fetch';
import 'regenerator-runtime/runtime';

import { isTopLevelApplication } from '@ovh-ux/manager-config';
import { defineApplicationVersion } from '@ovh-ux/request-tagger';

import { initShellClient } from '@ovh-ux/shell';

defineApplicationVersion(__VERSION__);

initShellClient('carbon-calculator').then((shellClient) => {
if (!isTopLevelApplication()) {
shellClient.ux.startProgress();
}
shellClient.environment.getEnvironment().then((environment) => {
environment.setVersion(__VERSION__);
import(`./config-${environment.getRegion()}`)
.catch(() => {})
.then(() => import('./app.module'))
.then(({ default: startApplication }) => {
startApplication(document.body, shellClient);
});
});
});
5 changes: 5 additions & 0 deletions packages/manager/apps/carbon-calculator/src/index.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@import 'bootstrap4/scss/_functions';
@import 'bootstrap4/scss/_variables';
@import 'bootstrap4/scss/_mixins';
@import 'bootstrap4/scss/_utilities';
@import 'bootstrap4/scss/_grid';
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export default {
EU: {
config: {
level2: '85',
},
},
CA: {
config: {
level2: '85',
},
},
US: {
config: {
level2: '57',
},
},
};
Loading
Loading