const result = data.reduce((acc, curr) => {
const {category, family, symbol, id} = curr;
acc.category[category] = acc.category[category] || {family: {}};
acc.category[category].family[family] = acc.category[category].family[family] || {symbol: {}};
acc.category[category].family[family].symbol[symbol] = acc.category[category].family[family].symbol[symbol] || {id: []};
acc.category[category].family[family].symbol[symbol].id.push(id);
return acc;
}, {category: {}});
const A = [{category: "Walls", id: "1"}, {category: "Walls", id: "2"}];
const B = [{category: "Window", id: "3"}, {category: "Walls", id: "4"}];
const C = [{category: "Walls", id: "5"}, {category: "Floor", id: "6"}];
const D = [{category: "Walls", id: "5"}, {category: "Walls", id: "6"}];
let newArr = [];
newArr['Walls'] = [];
newArr['Window'] = [];
newArr['Floor'] = [];
const allArr = {'A':A,'B':B,'C':C,'D':D};
for (let key in allArr) {
allArr[key].forEach(function (item) {
let tempItem = {'id': item.id, 'class': key};
newArr[item.category].push(tempItem);
});
}
for (let key in newArr) {
let section = $('<details></details>');
let summary = $('<summary>'+key+'</summary>');
section.appendTo('body');
section.append(summary);
newArr[key].forEach(function (item) {
console.log(item);
let newElement = $('<button class="'+item.class+'">'+item.id+'</button>');
section.append(newElement);
})
}
function makeDOM(html) { //Формируем DOM на основе структуры
for(let category in html) {
let det = document.createElement('details');
let cat = document.createElement('summary');
cat.innerText = category;
det.appendChild(cat);
html[category].forEach(o=>{
let button = document.createElement('button');
button.className = o.k;
button.innerText = o.id;
det.appendChild(button);
});
document.body.appendChild(det);
}
}
let html = {};
function makeButton(o) { //Формируем структуру
if (typeof o !== "object") return;
if (o instanceof Array) {
let k = o[o.length-1];
o.forEach(e=>{e.k=k,makeButton(e)});
return;
}
if (!o.id) {
for(let k in o) makeButton(o[k].concat([k]));
return;
}
let summary;summary = html[o.category] ||(summary = html[o.category] = []);
summary.push({k:o.k,id:o.id});
}
window.addEventListener('DOMContentLoaded',e=>{
makeButton({A:A,B:B,C:C,D:D});
makeDOM(html);
});
// это начальный индекс модели
const i = 0;
// коллбэк на успешную загрузку
const onDocumentLoadSuccess = () => {
i++;
(if arrId[i]) {
loader(i);
} else {
alert('все модели загружены');
}
};
// функция принимает индекс модели в массиве и запускает лоадер
const loader = (modelIndex) => {
Autodesk.Viewing.Document.load(arrId[modelIndex], onDocumentLoadSuccess, onDocumentLoadFailure);
};
// запускаем лоадер для нулевого элемента
loader(i);
const arrOne = [
{ group: "Dog", key: "bad", value: "7" },
{ group: "Cat", key: "dear", value: "13" },
{ group: "Cat", key: "good", value: "20" },
];
const arrTwo = [
{ group: "Dog", key: "bad", value: "265" },
{ group: "Cat", key: "dear", value: "529" },
{ group: "Cat", key: "good", value: "956" },
]
let arrThree = [];
arrOne.forEach((itm, i) => {
arrThree.push(Object.assign({}, itm, arrTwo[i]));
});
console.log(arrThree);
function diffCats(arr1, arr2) {
return arr1.filter(obj1 => {
return !arr2.some(obj2 => obj1.Category === obj2.Category && obj1.Value === obj2.Value);
});
}
const arrUniq1 = diffCats(arrFirst, arrSecond);
const arrUniq2 = diffCats(arrSecond, arrFirst);
const maths = document.querySelector('#Maths');
let doMinus = false
maths.onclick = function() {
let [a, b] = [3, 1];
if (!doMinus) {
console.log(a + b) // 4 ;
doMinus = true
} else {
console.log(a - b) // 2
}
};
[
{
"title": "Walls",
"children": [
{
"title": "Basic Wall",
"children": [
.....
let data = {...};
let html = '';
for (let k in data) {
if (!data.hasOwnProperty(k)) continue;
let item = data[k];
html += '<ul>';
html += '<li>'+item['category']+'</li>';
html += '<li>'+item['symbol']+'</li>';
// ...
html += '</ul>';
}
document.getElementById('differencesDiv').innerHTML = html;
const notUniqueRevitids = data
.reduce((acc, obj) => {
if (acc[0].size === acc[0].add(obj.revitid).size) {
acc[1].add(obj.revitid);
}
return acc;
}, [new Set(), new Set()])[1];
const uniqueObj = data.filter(obj => !notUniqueRevitids.has(obj.revitid));
const count = arr.reduce((acc, n) => (acc[n.revitid] = (acc[n.revitid] || 0) + 1, acc), {});
const unique = Object.entries(count).filter(n => n[1] === 1).map(n => n[0]);
const newArr = arr.filter(n => unique.includes(n.revitid));
const duplicate = arr.reduce((acc, n) => (acc[n.revitid] = acc.hasOwnProperty(n.revitid), acc), {});
const newArr = arr.filter(n => !duplicate[n.revitid]);
const newArr = arr.filter(function(n) {
return !this.get(n.revitid);
}, arr.reduce((acc, { revitid: n }) => acc.set(n, acc.has(n)), new Map));
const newArr = arr.filter((n, i, a) => a.filter(m => m.revitid === n.revitid).length === 1);
const newArr = Object
.values(arr.reduce((acc, n) => (acc[n.revitid] = acc[n.revitid] ? 1 : n, acc), {}))
.filter(n => n !== 1);
const newArr = Object
.values(arr.reduce((acc, n) => ((acc[n.revitid] = acc[n.revitid] || []).push(n), acc), {}))
.flatMap(n => n.length === 1 ? n : []);
const path = require('path');
const express = require('express'); // For web server
const bodyParser = require('body-parser'); // Receive JSON format
const querystring = require('querystring');
// Set up Express web server
var app = express();
app.use(bodyParser.json());
// this line say of server, that we run server.js he open html file from public directory
app.use(express.static(path.join(__dirname, 'public'))); // it was static(__ + 'public or www')
// let's importing config.js file where are the configuration for dotenv/env and credentials_id/secret/url/PORT and scopes
const config = require('./config');
const PORT = config.credentials.PORT; // import from bim start.js
const scopes = 'data:read data:write data:create bucket:create bucket:read';
var indRouter = require('./routes/indRouter');
indRouter(app);
app.use((err, req, res, next) => {
console.error(err);
res.status(err.statusCode).json(err);
});
// This is for web server to start listening to port 3000
app.listen(PORT, () => {
if (process.env.FORGE_CLIENT_ID == null || process.env.FORGE_CLIENT_SECRET == null) {
console.log('*****************\nWARNING: Client ID & Client Secret not defined as environment variables.\n*****************');
}
console.log(`Server listening on port ${PORT}`);
});
var oauth = require('./oauth');
var bucketCreate = require('./bucketCreate');
var Axios = require('axios');
var publ = require('./publ');
var detail = require('./detail');
module.exports = function(app) {
app.get('/api/forge/oauth', function (req, res) {
oauth()
.then(function (response) {
// Success
var access_token = response.data.access_token;
Axios.defaults.headers.common['Authorization'] = 'Bearer ' + access_token;
//console.log(response);
res.redirect('/api/forge/datamanagement/bucket/create');
})
.catch(function (error) {
// Failed
console.log(error);
res.send('Failed to authenticate');
});
});
app.get('/api/forge/datamanagement/bucket/create', function (req, res) {
bucketCreate()
.then(function (response) {
// Success
//console.log(response);
res.redirect('/api/forge/datamanagement/bucket/detail');
})
.catch(function (error) {
if (error.response && error.response.status == 409) {
console.log('Bucket already exists, skip creation.');
res.redirect('/api/forge/datamanagement/bucket/detail');
}
// Failed
console.log(error);
res.send('Failed to create a new bucket');
});
});
app.get('/api/forge/oauth/public', function (req, res) {
// Limit public token to Viewer read only
publ()
.then(function (response) {
// Success
//console.log(response);
res.json({ access_token: response.data.access_token, expires_in: response.data.expires_in });
})
.catch(function (error) {
// Failed
console.log(error);
res.status(500).json(error);
});
});
app.get('/api/forge/datamanagement/bucket/detail', function (req, res) {
detail()
.then(function (response) {
// Success
console.log(response);
res.redirect('/upload.html');
})
.catch(function (error) {
// Failed
console.log(error);
res.send('Failed to verify the new bucket');
});
});
};
const Axios = require('axios');
const querystring = require('querystring');
const config = require('../config');
module.exports = function() {
return Axios({
method: 'POST',
url: 'https://developer.api.autodesk.com/authentication/v1/authenticate',
headers: {
'content-type': 'application/x-www-form-urlencoded',
},
data: querystring.stringify({
client_id: config.credentials.client_id,
client_secret: config.credentials.client_secret,
grant_type: 'client_credentials',
scope: config.scopes.internal
})
});
};
const Axios = require('axios');
const config = require('../config');
// Prefix with your ID so the bucket key is unique across all buckets on all other accounts
const bucketKey = config.credentials.client_id.toLowerCase() + '_my_first_full_viewer_bucket';
const policyKey = 'transient'; // Expires in 24hr
// Create an application shared bucket using access token from previous route
// We will use this bucket for storing all files in this tutorial
module.exports = function() {
return Axios({
method: 'POST',
url: 'https://developer.api.autodesk.com/oss/v2/buckets',
headers: {
'content-type': 'application/json',
//Authorization: 'Bearer ' + access_token
},
data: JSON.stringify({
'bucketKey': bucketKey,
'policyKey': policyKey
})
});
};
const Axios = require('axios');
const querystring = require('querystring');
const config = require('../config');
module.exports = function() {
return Axios({
method: 'POST',
url: 'https://developer.api.autodesk.com/authentication/v1/authenticate',
headers: {
'content-type': 'application/x-www-form-urlencoded',
},
data: querystring.stringify({
client_id: config.credentials.client_id,
client_secret: config.credentials.client_secret,
grant_type: 'client_credentials',
scope: 'viewables:read'
})
});
};
var Axios = require('axios');
const config = require('../config');
// Prefix with your ID so the bucket key is unique across all buckets on all other accounts
const bucketKey = config.credentials.client_id.toLowerCase() + '_my_first_full_viewer_bucket';
module.exports = function() {
return Axios({
method: 'GET',
url: 'https://developer.api.autodesk.com/oss/v2/buckets/' + encodeURIComponent(bucketKey) + '/details',
//headers: {
//Authorization: 'Bearer ' + access_token
//}
});
};
const path = require('path');
const express = require('express'); // For web server
const Axios = require('axios'); // A Promised base http client
const bodyParser = require('body-parser'); // Receive JSON format
const querystring = require('querystring');
// Set up Express web server
let app = express();
app.use(bodyParser.json());
// this line say of server, that we run server.js he open html file from public directory
app.use(express.static(path.join(__dirname, 'public'))); // it was static(__ + 'public or www')
// let's importing config.js file where are the configuration for dotenv/env and credentials_id/secret/url/PORT and scopes
const config = require('./config');
const PORT = config.credentials.PORT; // import from bim start.js
const scopes = 'data:read data:write data:create bucket:create bucket:read';
var oauth = require('./routes/oauth');
var bucketCreate = require('./routes/bucketCreate');
app.get('/api/forge/oauth', function(req, res) {
oauth()
.then(function (response) {
// Success
// let's save token into the varible access_token
// Then, the app is routed to, which creates a shared bucket for our app.
var access_token = response.data.access_token;
bucketCreate(access_token)
.then(function (response) {
// Success
console.log(response);
res.redirect('/api/forge/datamanagement/bucket/detail');
})
.catch(function (error) {
if (error.response && error.response.status == 409) {
console.log('Bucket already exists, skip creation.');
res.redirect('/api/forge/datamanagement/bucket/detail');
}
// Failed
console.log(error);
res.send('Failed to create a new bucket');
});
})
.catch(function (error) {
// Failed
console.error(error);
res.send('Failed to authenticate');
});
});
app.use((err, req, res, next) => {
console.error(err);
res.status(err.statusCode).json(err);
});
// This is for web server to start listening to port 3000
app.listen(PORT, () => {
if (process.env.FORGE_CLIENT_ID == null || process.env.FORGE_CLIENT_SECRET == null) {
console.log('*****************\nWARNING: Client ID & Client Secret not defined as environment variables.\n*****************');
}
console.log(`Server listening on port ${PORT}`);
});
/*
* Authentication
*/
const Axios = require('axios');
const querystring = require('querystring');
const config = require('../config');
module.exports = function() {
return Axios({
method: 'POST',
url: 'https://developer.api.autodesk.com/authentication/v1/authenticate',
headers: {
'content-type': 'application/x-www-form-urlencoded',
},
data: querystring.stringify({
client_id: config.credentials.client_id,
client_secret: config.credentials.client_secret,
grant_type: 'client_credentials',
scope: config.scopes.internal
})
});
};
/*
* Bucket Creation
*/
const Axios = require('axios');
const config = require('../config');
// Prefix with your ID so the bucket key is unique across all buckets on all other accounts
const bucketKey = config.credentials.client_id.toLowerCase() + '_my_first_full_viewer_bucket';
const policyKey = 'transient'; // Expires in 24hr
// Create an application shared bucket using access token from previous route
// We will use this bucket for storing all files in this tutorial
module.exports = function(access_token) {
console.log('!!!!!!!!!!!!! ' + access_token);
return Axios({
method: 'POST',
url: 'https://developer.api.autodesk.com/oss/v2/buckets',
headers: {
'content-type': 'application/json',
Authorization: 'Bearer ' + access_token
},
data: JSON.stringify({
'bucketKey': bucketKey,
'policyKey': policyKey
})
});
};