Skip to content

Instantly share code, notes, and snippets.

View davecra's full-sized avatar
💭
Coding for arrays

David E. Craig davecra

💭
Coding for arrays
View GitHub Profile
@davecra
davecra / client.js
Created October 22, 2023 19:58
Client.js for Power-Up
/* global TrelloPowerUp */
/// <reference path="../types/trello.d.js" />
import Common from './common/common';
/** @type {TrelloPowerUp} */
const tpu = window.TrelloPowerUp;
tpu.initialize({
'board-buttons': async (t) => await getBoardButton(t),
});
/**
* Returns the board button
@davecra
davecra / common.js
Created October 22, 2023 19:57
Common.js for Power-Up
const PACKAGE = require('../../package.json');
/**
* CommonFunctions to be shared across all the project
*/
export default class Common {
/** @type {String} */
static APPNAME = PACKAGE.appName;
/** @type {String} */
static VERSION = PACKAGE.version;
/** @type {String} */
@davecra
davecra / index.html
Created October 22, 2023 19:55
index.html for Trello Power-Up
<!DOCTYPE html>
<html lang="en-us">
<head>
<meta http-equiv="Cache-control" content="no-cache"/>
<meta http-equiv="pragma" content="no-cache"/>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<!-- if you want Trello sizeTo to work correctly, you need to keep this -->
<link crossorigin="anonymous" rel="stylesheet" href="https://p.trellocdn.com/power-up.min.css">
<title>Power-Up</title>
@davecra
davecra / commands.js
Created September 13, 2023 13:33
JSRuntime to get it working
/**
* Checks to see if we are running in Windows Outlook
* @returns {Boolean}
*/
function isPC() {
try {
if (Office.context.platform === Office.PlatformType.PC || Office.context.platform === null) {
return true;
} else {
return false;
@davecra
davecra / onready.js
Created September 13, 2023 13:30
Office OnReady in JSRuntime
/**
* Ensures the Office.js library is loaded.
*/
Office.onReady((info) => {
/**
* Maps the event handler name specified in the manifest's LaunchEvent element to its JavaScript counterpart.
* This ensures support in Outlook on Windows.
*/
if (Office.context.platform === Office.PlatformType.PC || Office.context.platform == null) {
Office.actions.associate("onMessageSendHandler", onMessageSendHandler);
@davecra
davecra / inline2.js
Last active May 12, 2023 22:05
inline2.js
export default class MyClassToCallTheServer {
#internvalValue = null;
constrcutor() {
// this.#internalValue = await this.#callTheServer(); <-- the await will fail to compile
this.#internalValue = this.#callTheServer();
}
doSomethingWithTheServerData = () => {
// the #internalValue is still null becasue we could not await in the constructor
return this.#internalValue;
}
@davecra
davecra / inline3.js
Last active May 12, 2023 22:04
inline3.js
export default class MyClassToCallTheServer {
#internvalValue = null;
#loading = false;
constrcutor() {
this.#internalValue = this.#callTheServer();
}
doSomethingWithTheServerData = async () => {
while(this.#loading) await new Promise(resolve => setTimeout(resolve, 10));
// the #internalValue is not null because we waited
return this.#internalValue;
@davecra
davecra / inline4.js
Created May 12, 2023 21:58
inline4.js
const myObj = new MyClassToCallTheServer();
let someValue = await myObj.doSomegthingWithTheServerData();
@davecra
davecra / inline1.js
Last active May 12, 2023 21:55
inline1.js
const myObj = new MyClassToCallTheServer();
let someValue = myObj.doSomegthingWithTheServerData();
@davecra
davecra / getUsername.js
Created July 27, 2020 14:51
Gets the username for the current user using the SSO API
export async function getUserName() {
try {
let tokenData = await OfficeRuntime.auth.getAccessToken({ allowSignInPrompt: false, forMSGraphAccess: true });
var parts = tokenData.split(".");
var token = JSON.parse(atob(parts[1]));
return token.preferred_username;
}
catch (exception) {
console.log(exception.message);
}